1 Reply Latest reply on Dec 12, 2016 11:30 AM by Mario Zahren

    Stop program until error code has been eliminated

    Mario Zahren

      Hello all,

      I have a problem with the ".LockFile" Method because the file is open in SolidWorks. The error code is 0x8004020B.
      In my code, I want to display a messagebox that does not disappear until the drawing has been closed by the user. How can I do this?

      Here is my code:

       

      ...
                  ...
                  string newComment = serialNbrValueValue + " | " + CommentVal;
                  IEdmEnumeratorVariable5 varEnum3 = default(IEdmEnumeratorVariable5);
                  DialogResult dialogResult = MessageBox.Show("Die Datei " + File.Name + " ist geöffnet und muss unbedingt geschlossen werden!", "Datei " + File.Name + " schließen", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                  if (dialogResult == DialogResult.OK)
                  {
                      try
                      {
                          File.LockFile(ppoRetParentFolder.ID, 0, (int)EdmLockFlag.EdmLock_Simple);
                      }
                      catch (COMException exp)
                      {
                          string errorName, errorDesc;
                          vault.GetErrorString(exp.ErrorCode, out errorName, out errorDesc);
                          vault.MsgBox(0, errorDesc, EdmMBoxType.EdmMbt_OKOnly, errorName);
                      }
                      ...
      

       

      Any help would be appreciated.

      Thanks, Mario

        • Re: Stop program until error code has been eliminated
          Mario Zahren

          Probably not the most beautiful solution but this is how it works:

           

                      string newComment = serialNbrValueValue + " | " + CommentVal;
                      IEdmEnumeratorVariable5 varEnum3 = default(IEdmEnumeratorVariable5);
                      do
                      {
                          string errorName = "";
                          string errorDesc = "";
                          try
                          {
                              File.LockFile(ppoRetParentFolder.ID, 0, (int)EdmLockFlag.EdmLock_Simple);
                          }
                          catch (COMException exp)
                          {
                              vault.GetErrorString(exp.ErrorCode, out errorName, out errorDesc);
                          }
                          if (errorName == "")
                          {
                              break;
                          }
                          else
                          {
                              DialogResult dialogResult = MessageBox.Show("Die Datei " + File.Name + " ist geöffnet und muss unbedingt geschlossen werden!", "Datei " + File.Name + " schließen", 
                                  MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1);
                          }
                      } while (true);
          

           

          For a more beautiful solution I would be grateful ...