2 Replies Latest reply on Nov 30, 2017 8:22 AM by R. Klingel

    Solidworks PDM API static AddFiles method (C#)

    R. Klingel


      I'm looking for a way to check in files posted from a webserver.


      The current method I'm looking into is writing the files to an EPDM Vault via the webserver and then checking it in using the "Folder.AddFiles" method using a C# console application.

      The console application is running in a static context and I want to pass it via args[] the path of the file, and some additional info to fill in the file options like e.g. mbsNewName.

      I can log in to the vault and read file descirptions but now the "Folder.AddFiles" method expects the window handle, the files options and a callback.

      Which I don't have in this context.


      I tried passing it the handle I got from "GetConsoleWindow" and implementing a static, empty "IEdmCallback6".


      To keep things short:

      Is there an example somewhere for this ?

      Is there any other way like e.g. using the EPDM Web client to do so ?

      Finally this should result in a restful api where I can post files to the server.


      Thank you in advance!

        • Re: Solidworks PDM API static AddFiles method (C#)
          Simon Turner

          Just pass in 0 (zero) for the window handle.

          The callback is optional, but if you want to use it, you provide it yourself by creating a class which implements the IEdmCallback6 interface.

          There is an example here:

          2017 SOLIDWORKS API Help - Add Files to Vault Example (C#)

            • Re: Solidworks PDM API static AddFiles method (C#)
              R. Klingel

              Thank you! This lead me in the right direction.

              For alle looking for the same thing, here's the code.

              There's still the error handling missing but the "happy path" is working.


              static void Main(string[] args)








                              if (args.Length != 4)


                                  Console.WriteLine("Usage: \"Source Path\" \"Source_name\" \"Target Path\" \"Target Name\"");



                              string source_path = "C:\\temp";

                              string source_filename = "test_123.txt";

                              string target_path = "Target\\Folder";

                              string target_filename = "Result_data.txt";

                              int errorcode;

                              IEdmFolder5 ppoRetParentFolder;



                              //Create a file vault interface and log into a vault

                              IEdmVault5 vault1 = new EdmVault5();

                              IEdmVault8 vault2 = null;

                              if (vault1 == null)


                                  vault1 = new EdmVault5();


                              vault2 = (IEdmVault8)vault1;

                              vault1.Login("Name", "Password", "Vaultname");



                              IEdmFile11 aFile = default(IEdmFile11);



                              // Get the Root of the vault

                              IEdmFolder8 Folder = default(IEdmFolder8);

                              Folder = (IEdmFolder8)vault2.RootFolder;



                              // Get target folder

                              IEdmFolder8 target_folder = default(IEdmFolder8);

                              target_folder = (IEdmFolder8)vault2.GetFolderFromPath(Folder.LocalPath + "\\" + target_path);



                              // Copy the file to the folder

                              target_folder.AddFile2(0, source_path+"\\" + source_filename,out errorcode,target_filename, (int)EdmAddFlag.EdmAdd_Simple);



                              // Simple check in

                              aFile = (IEdmFile11)vault2.GetFileFromPath(Folder.LocalPath + "\\" + target_path + "\\" + target_filename, out ppoRetParentFolder);

                              aFile.UnlockFile(0, "");




                              Console.WriteLine("File added sucessufully...");







                          catch (System.Runtime.InteropServices.COMException ex)


                              Console.WriteLine("HRESULT = 0x" + ex.ErrorCode.ToString("X") + "\n" + ex.Message);


                          catch (Exception ex)