217 lines
14 KiB
HTML
217 lines
14 KiB
HTML
<html xmlns:v="urn:schemas-microsoft-com:vml"
|
|
xmlns:o="urn:schemas-microsoft-com:office:office"
|
|
xmlns:w="urn:schemas-microsoft-com:office:word"
|
|
xmlns="http://www.w3.org/TR/REC-html40">
|
|
|
|
<head>
|
|
<title>Stand-alone Applications (C#)</title>
|
|
<meta name=MS-HKWD content="Stand-alone applications">
|
|
<meta name=MS-HKWD content="Stand-alone applications, C#">
|
|
<meta http-equiv="Content-Language" content="en-us">
|
|
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
|
|
<link rel="stylesheet" type="text/css" href="ApiHelp.css">
|
|
<style type="text/css">
|
|
.auto-style1 {
|
|
font-family: Verdana;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<h1><span style="font-weight: normal; font-size: 7.5pt;">SOLIDWORKS PDM Professional API Help</span></h1>
|
|
<h1>Stand-alone Applications (C#)</h1>
|
|
|
|
<body bgcolor=white lang=SV link=blue vlink=purple style='tab-interval:65.2pt'>
|
|
|
|
<div class=Section1>
|
|
|
|
<p style='margin-bottom:12.0pt'>
|
|
This topic describes how to create a C# stand-alone application that logs into
|
|
a SOLIDWORKS PDM Professional file vault and lists the files in the root folder. </p>
|
|
<ol>
|
|
<li class=kadov-p>
|
|
<p style='margin-bottom:12.0pt'>
|
|
Start up Microsoft Visual Studio.</p></li>
|
|
<li class=kadov-p>
|
|
<p style='margin-bottom:12.0pt'>
|
|
Click <b>File > New > Project</b> > <b>Visual C# > Windows Forms App
|
|
(.NET Framework)</b>.</p>
|
|
<ol type="a">
|
|
<li>
|
|
<p style='margin-bottom:12.0pt'>Type <b>StandaloneApplicationCSharp</b> in <b>Name</b>.</p>
|
|
</li>
|
|
<li>
|
|
<p style='margin-bottom:12.0pt'>Click <b>Browse</b> and navigate to the folder where to create the
|
|
project.</p></li>
|
|
<li>
|
|
<p style='margin-bottom:12.0pt'>Click <b>OK</b>.</p></li>
|
|
<li>
|
|
<p style='margin-bottom:12.0pt'>Right-click the name of your project in the Solution Explorer and select
|
|
<b>Add Reference</b>
|
|
to add the SOLIDWORKS PDM Professional primary assembly interop to your project. </p>
|
|
<div class="Section1">
|
|
<ol>
|
|
<li><font style="FONT-SIZE: 8pt" face="Verdana">Browse to the top
|
|
folder of your SOLIDWORKS PDM Professional installation.</font> <br>
|
|
</li>
|
|
<li><font style="FONT-SIZE: 8pt" face="Verdana">Locate and click <b>
|
|
EPDM.Interop.epdm.dll</b>.<br>
|
|
</font> </li>
|
|
<li><font style="FONT-SIZE: 8pt" face="Verdana">Click <b>Open.</b></font>
|
|
<br>
|
|
</li>
|
|
<li><font style="FONT-SIZE: 8pt" face="Verdana">Click <b>Add.</b></font>
|
|
<br>
|
|
</li>
|
|
<li><font style="FONT-SIZE: 8pt" face="Verdana">Click <b>Close</b>.<br></font></li>
|
|
</ol>
|
|
</div>
|
|
</li>
|
|
</ol>
|
|
</li>
|
|
<li class=kadov-p>
|
|
<p style='margin-bottom:12.0pt'>
|
|
<span class="auto-style1">C</span><span style="font-family: Verdana" lang="en-us">hange the
|
|
version of the .NET Framework and the </span>
|
|
<span style="font-family: Verdana">platform </span>
|
|
<span style="font-family: Verdana" lang="en-us">target.</span></p>
|
|
<ol>
|
|
<li type="a"><font style="FONT-SIZE: 8pt" face="Verdana">Click <b>Project ></b>
|
|
</font><b>StandaloneApplicationCSharp</b><font style="FONT-SIZE: 8pt" face="Verdana">
|
|
<b>Properties > Build</b> and set <b>Platform target </b>to<b> Any CPU</b>.<b><br>
|
|
</b></font></li>
|
|
<li type="a"><font style="FONT-SIZE: 8pt" face="Verdana">Click <b>Application</b>
|
|
and keep suggested <b>Target framework</b> or change it to <b>.NET Framework 4.5
|
|
</b>(or later).<br></font></li>
|
|
<li type="a"><span class="auto-style1">De-select <strong>Prefer 32-bit</strong>.</span><font style="FONT-SIZE: 8pt" face="Verdana"><b><br>
|
|
</b></font></li>
|
|
<li type="a"><font style="FONT-SIZE: 8pt" face="Verdana">Click <b>Yes</b>.<b><br> </b></font></li>
|
|
</ol>
|
|
</li>
|
|
<li class=kadov-p>
|
|
<p style='margin-bottom:12.0pt'>
|
|
<span style="font-family: Verdana" lang="en-us">Right-click <b>Form1.cs</b>
|
|
in the Solution Explorer and click <b>View Designer</b>.</span></p>
|
|
</li>
|
|
<li class=kadov-p>
|
|
<p style='margin-bottom:12.0pt'>
|
|
<span style="font-family: Verdana" lang="en-us">Click <b>View > Toolbox</b>.</span></p>
|
|
</li>
|
|
<li class=kadov-p>
|
|
<p style='margin-bottom:12.0pt'>
|
|
<span style="font-family: Verdana" lang="en-us">Drag </span><span lang=EN-US
|
|
style='font-family:Verdana'> a button from the Toolbox onto the form.</span></p>
|
|
</li>
|
|
<li class=kadov-p>
|
|
<p style='margin-bottom:12.0pt'><span lang="en-us">Double-click the button
|
|
to open <b>Form1.cs </b>and replace all of the code in the code window with</span><span lang=EN-US> the following
|
|
code. </span></p></li>
|
|
</ol>
|
|
<blockquote>
|
|
<pre style="font-family: Courier New; font-size: 13; color: black; background: white"><span style="color:blue;">using</span> System;
|
|
<span style="color:blue;">using</span> System.Collections.Generic;
|
|
<span style="color:blue;">using</span> System.ComponentModel;
|
|
<span style="color:blue;">using</span> System.Data;
|
|
<span style="color:blue;">using</span> System.Drawing;
|
|
<span style="color:blue;">using</span> System.Linq;
|
|
<span style="color:blue;">using</span> System;
|
|
<span style="color:blue;">using</span> System.Windows.Forms;
|
|
<span style="color:blue;">using</span> EPDM.Interop.epdm;
|
|
|
|
<span style="color:blue;">namespace</span> StandaloneApplicationCSharp
|
|
{
|
|
<span style="color:blue;">public</span> <span style="color:blue;">partial</span> <span style="color:blue;">class</span> <span style="color:#2b91af;">Form1</span> : <span style="color:#2b91af;">Form</span>
|
|
{
|
|
<span style="color:blue;">public</span> Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
<span style="color:blue;">private</span> <span style="color:blue;">void</span> button1_Click(System.<span style="color:#2b91af;">Object</span> sender, System.<span style="color:#2b91af;">EventArgs</span> e)
|
|
{
|
|
<span style="color:blue;">try</span>
|
|
{
|
|
|
|
<span style="color:green;">//Create a file vault interface and log into a vault</span>
|
|
<span style="color:#2b91af;">IEdmVault5</span> vault = <span style="color:blue;">new</span> <span style="color:#2b91af;">EdmVault5</span>();
|
|
vault.LoginAuto(<span style="color:#a31515;">"<i>MyVaultName</i>"</span>, <span style="color:blue;">this</span>.Handle.ToInt32());
|
|
|
|
<span style="color:green;">//Get the vault's root folder interface</span>
|
|
<span style="color:blue;">string</span> message = <span style="color:#a31515;">""</span>;
|
|
<span style="color:#2b91af;">IEdmFile5</span> file = <span style="color:blue;">null</span>;
|
|
<span style="color:#2b91af;">IEdmFolder5</span> folder = <span style="color:blue;">null</span>;
|
|
folder = vault.RootFolder;
|
|
|
|
<span style="color:green;">//Get position of first file in the root folder</span>
|
|
<span style="color:#2b91af;">IEdmPos5</span> pos = <span style="color:blue;">null</span>;
|
|
pos = folder.GetFirstFilePosition();
|
|
<span style="color:blue;">if</span> (pos.IsNull)
|
|
{
|
|
message = (<span style="color:#a31515;">"The root folder of your vault does not contain any files."</span>);
|
|
<span style="color:#2b91af;">MessageBox</span>.Show(message);
|
|
<span style="color:blue;">return</span>;
|
|
}
|
|
message = (<span style="color:#a31515;">"The root folder of your vault contains these files: "</span> + <span style="color:#a31515;">"\n"</span>);
|
|
<span style="color:blue;">while</span> (!pos.IsNull)
|
|
{
|
|
file = folder.GetNextFile(pos);
|
|
message = message + file.Name + <span style="color:#a31515;">"\n"</span>;
|
|
}
|
|
|
|
<span style="color:green;">//Show the names of all files in the root folder</span>
|
|
<span style="color:#2b91af;">MessageBox</span>.Show(message);
|
|
|
|
}
|
|
|
|
<span style="color:blue;">catch</span> (System.Runtime.InteropServices.<span style="color:#2b91af;">COMException</span> ex)
|
|
{
|
|
<span style="color:#2b91af;">MessageBox</span>.Show(<span style="color:#a31515;">"HRESULT = 0x"</span> + ex.ErrorCode.ToString(<span style="color:#a31515;">"X"</span>) + <span style="color:#a31515;">"\n"</span> + ex.Message);
|
|
}
|
|
<span style="color:blue;">catch</span> (<span style="color:#2b91af;">Exception</span> ex)
|
|
{
|
|
<span style="color:#2b91af;">MessageBox</span>.Show(ex.Message);
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
</pre>
|
|
</blockquote>
|
|
<ol style="font-family: Verdana; font-size: 8pt" start="8">
|
|
<li>
|
|
<p class="APICODE" style="line-height: 11.3pt"><span lang="en-us">
|
|
<font face="Verdana" style="font-size: 8pt">Replace </font><i>
|
|
<font face="Courier New" color="#A31515" size="2">MyVaultName</font></i><font face="Verdana" style="font-size: 8pt"> in
|
|
the code with the name of a SOLIDWORKS PDM Professional vault on your
|
|
computer.</font></span></li>
|
|
<li>
|
|
<p class="APICODE" style="line-height: 11.3pt"><span lang="en-us">
|
|
<font face="Verdana" style="font-size: 8pt">Click <b>Debug >
|
|
Start Debugging</b> or press <b>F5</b>.</font></span><ol style="font-family: Verdana; font-size: 8pt" type="a">
|
|
<li>
|
|
<p class="APICODE" style="line-height: 11.3pt"><span lang="en-us">
|
|
<font face="Verdana" style="font-size: 8pt">Click <b>Button1</b> on the
|
|
form.<br><br>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.</font></span></li>
|
|
<li>
|
|
<p class="APICODE" style="line-height: 11.3pt"><span lang="en-us">
|
|
<font face="Verdana" style="font-size: 8pt">Close the form.</font></span></li>
|
|
</ol></li>
|
|
<li>
|
|
<p class="APICODE" style="line-height: 11.3pt"><span lang="en-us">
|
|
<font face="Verdana" style="font-size: 8pt">Click <b>File > Save All</b>.</font></span></li>
|
|
</ol>
|
|
<h2 style='background:white'>
|
|
<span lang=EN-GB style='font-family:Verdana;mso-ansi-language:EN-GB'><o:p> See
|
|
Also</o:p></span></h2>
|
|
<p style='background:white'><a href="StandAloneApp.htm">Stand-alone Applications
|
|
(VB.NET)</a></p>
|
|
<p style='background:white'><a href="StandAloneAppCpp.htm">Stand-alone Applications (C++)</a></p>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
|
|
</html>
|