This topic describes how to create a C# stand-alone application that logs into
a SOLIDWORKS Enterprise PDM file vault and lists the files in the root folder.
-
Start up Microsoft Visual Studio 2010.
-
Click File > New > Project > Visual C# > Windows Forms Application.
-
Type StandaloneApplicationCSharp in Name.
-
Click Browse and navigate to the folder where to create the
project.
-
Click OK.
-
Right-click the name of your project in the Solution Explorer and select
Add Reference
to add the SOLIDWORKS Enterprise PDM primary assembly interop to your project.
- Browse to the top
folder of your SOLIDWORKS Enterprise PDM installation, typically
C:\Program Files\SOLIDWORKS Enterprise PDM.
- Locate and click
EPDM.Interop.epdm.dll.
- Click Open.
- Click Add.
- Click Close.
-
If using the SOLIDWORKS
Enterprise PDM .NET Framework 4.0 primary interop assembly, change the
version of the .NET Framework and the target.
- Click Project >
StandaloneApplicationCSharp
Properties > Build and set Platform target to Any CPU.
- Click Application
and set Target framework to .NET Framework 4.
- Click Yes.
-
Right-click Form1.cs
in the Solution Explorer and click View Designer.
-
Click View > Toolbox.
-
Drag a button from the Toolbox onto the form.
-
Double-click the button
to open Form1.cs and replace all of the code in the code window with the following
code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System;
using System.Windows.Forms;
using EPDM.Interop.epdm;
namespace StandaloneApplicationCSharp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(System.Object sender, System.EventArgs e)
{
try
{
//Create a file vault interface and log into a vault
IEdmVault5 vault = new EdmVault5();
vault.LoginAuto("MyVaultName", this.Handle.ToInt32());
//Get the vault's root folder interface
string message = "";
IEdmFile5 file = null;
IEdmFolder5 folder = null;
folder = vault.RootFolder;
//Get position of first file in the root folder
IEdmPos5 pos = null;
pos = folder.GetFirstFilePosition();
if (pos.IsNull)
{
message = ("The root folder of your vault does not contain any files.");
MessageBox.Show(message);
return;
}
message = ("The root folder of your vault contains these files: " + "\n");
while (!pos.IsNull)
{
file = folder.GetNextFile(pos);
message = message + file.Name + "\n";
}
//Show the names of all files in the root folder
MessageBox.Show(message);
}
catch (System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + "\n" + ex.Message);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
-
Replace
MyVaultName in
the code with the name of a SOLIDWORKS Enterprise PDM vault on your
computer.
-
Click Debug >
Start Debugging or press F5.
-
Click Button1 on the
form.
A message box is displayed that either contains the names of
the files in the root folder of the specified vault or informs you that the
root folder of the specified vault does not contain any files.
-
Close the form.
-
Click File > Save All.
See
Also
Stand-alone Applications
(VB.NET)
Stand-alone Applications (C++)