Hide Table of Contents

Batch Check Out Files Example (VB.NET)

This example shows how to check out several files from the vault in one batch.

NOTE: If using the .NET Framework 4.0 primary interop assembly provided with SolidWorks Enterprise PDM, see Using .NET Framework 4.0 in Stand-alone Applications.

' Preconditions:
'  1. Start Microsoft Visual Studio 2010.
'     a. Click File > New > Project > Visual Basic > Windows Forms Application.
'     b. Type BatchGetFiles in Name.
'     c. Click Browse and navigate to the folder where to create the project.
'     d. Click OK
'     e. Click Show All Files in the Solution Explorer toolbar and expand 
'        Form1.vb in the Solution Explorer.
'     f. Replace the code in Form1.vb with this code.
'     g. To create the form, replace the code in Form1.Designer.vb with 
'        this code.

'  2. Add EPDM.Interop.epdm.dll as a reference (right-click the project
'     name in the Solution Explorer, click Add Reference, click 
'     Assemblies > Framework in the left-side panel, browse to the top folder of 
'     your SolidWorks Enterprise PDM installation, locate and click 
'     EPDM.Interop.epdm.dll, click Open, click Add, and click Close).
'  3. Right-click EPDM.Interop.epdm in References, click Properties, and set 
'     Embed Interop Types to False to handle methods that pass arrays of 
'     structures.
'  4. Ensure that the vault contains at least one checked-in file.

'  5. Click Debug > Start Debugging or press F5.
' Postconditions: 
'  1. The Check Out Files dialog box displays.

'     a. Select a vault view.
'     b. Click Select files to check out from vault.
'     c. In the Select File dialog:
'        1. Click a couple of files inside the vault.
'        2. Click Open.
'     d. Click Check out files from vault.
'  2. Click Check Out in the Check Out dialog box.
'  3. Close the Check Out Files dialog box.
'  4. Observe that the selected files are checked out of the selected vault.

Imports System.IO
Imports System.Xml.Serialization
Imports System.Collections
Imports System.Collections.Generic
Imports System.Data
Imports System.Diagnostics
Imports System.Windows.Forms
Imports System.ComponentModel
Imports EPDM.Interop.epdm
Public Class Form1
    Private vault1 As IEdmVault5 = Nothing
    Dim batchGetter As IEdmBatchGet
    Dim fileList As IEdmSelectionList6 = Nothing
    Dim poSel As EdmSelectionObject = Nothing
    Dim ppoSelection(10) As EdmSelItem
    Dim fileCount As Integer = 0
    Dim aFile As IEdmFile5
    Dim aFolder As IEdmFolder5
    Dim aPos As IEdmPos5
    Dim str As String
    Dim retVal As Boolean

    Public Sub Form1_Load(ByVal sender As System.ObjectByVal e As System.EventArgsHandles MyBase.Load
            Dim vault1 As IEdmVault5 = New EdmVault5()
            Dim vault As IEdmVault8 = DirectCast(vault1, IEdmVault8)
            Dim Views As EdmViewInfo() = Nothing
            vault.GetVaultViews(Views, False)
            For Each View As EdmViewInfo In Views
            If VaultsComboBox.Items.Count > 0 Then
                VaultsComboBox.Text = DirectCast(VaultsComboBox.Items(0), String)
            End If
        Catch ex As System.Runtime.InteropServices.COMException
            MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message)
        Catch ex As Exception
        End Try
    End Sub
    Public Sub SelectFiles_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles SelectFiles.Click
            Dim vault2 As IEdmVault7 = Nothing
            If vault1 Is Nothing Then
                vault1 = New EdmVault5()
            End If
            vault2 = DirectCast(vault1, IEdmVault7)
            If Not vault1.IsLoggedIn Then
                vault1.LoginAuto(VaultsComboBox.Text, Me.Handle.ToInt32())
            End If
            'Set the initial directory in the Select File dialog
            OpenFileDialog1.InitialDirectory = vault1.RootFolderPath
            'Show the Select File dialog
            Dim DialogResult As System.Windows.Forms.DialogResult = Nothing
            DialogResult = OpenFileDialog1.ShowDialog()
            batchGetter = vault2.CreateUtility(EdmUtility.EdmUtil_BatchGet)
            'If the user didn't click Open, no files were selected
            If Not (DialogResult = System.Windows.Forms.DialogResult.OK) Then
                ' do nothing
                Dim i As Integer = 0
                For Each FileName As String In OpenFileDialog1.FileNames
                    aFile = vault1.GetFileFromPath(FileName)
                    aPos = aFile.GetFirstFolderPosition
                    aFolder = aFile.GetNextFolder(aPos)
                    ppoSelection(i) = New EdmSelItem
                    ppoSelection(i).mlDocID = aFile.ID
                    ppoSelection(i).mlProjID = aFolder.ID
                    i = i + 1
                ' Add selections to the batch of files to check out
                batchGetter.AddSelection(vault1, ppoSelection)
            End If
        Catch ex As System.Runtime.InteropServices.COMException
            MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message)
        Catch ex As Exception
        End Try
    End Sub

    Public Sub BatchGet_Click(ByVal sender As System.ObjectByVal e As System.EventArgsHandles BatchGet.Click
            Dim vault2 As IEdmVault7 = Nothing
            If vault1 Is Nothing Then
                vault1 = New EdmVault5()
            End If
            vault2 = DirectCast(vault1, IEdmVault7)
            If Not vault1.IsLoggedIn Then
                vault1.LoginAuto(VaultsComboBox.Text, Me.Handle.ToInt32())
            End If
            If Not IsNothing(batchGetter) Then
                batchGetter.CreateTree(Me.Handle.ToInt32(), EdmGetCmdFlags.Egcf_Lock)
                fileCount = batchGetter.FileCount
                fileList = batchGetter.GetFileList(EdmGetFileListFlag.Egflf_GetLocked & EdmGetFileListFlag.Egflf_GetFailed & EdmGetFileListFlag.Egflf_GetRetrieved & EdmGetFileListFlag.Egflf_GetUnprocessed)
                aPos = fileList.GetHeadPosition()
                str = "Getting " & fileCount & " files: "
                While Not (aPos.IsNull())
                    fileList.GetNext2(aPos, poSel)
                    str = str + vbLf + poSel.mbsPath
                End While
                retVal = batchGetter.ShowDlg(Me.Handle.ToInt32()) ' No dialog if checking out only one file
                If (retVal) Then
                    batchGetter.GetFiles(Me.Handle.ToInt32(), Nothing)
                End If
            End If
        Catch ex As System.Runtime.InteropServices.COMException
            MessageBox.Show("HRESULT = 0x" + ex.ErrorCode.ToString("X") + " " + ex.Message)
        Catch ex As Exception
        End Try
    End Sub

End Class



Back to top


<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form
    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing AndAlso components IsNot Nothing Then
            End If
        End Try
    End Sub
    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer
    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.VaultsLabel = New System.Windows.Forms.Label()
        Me.VaultsComboBox = New System.Windows.Forms.ComboBox()
        Me.SelectFiles = New System.Windows.Forms.Button()
        Me.File1List = New System.Windows.Forms.ListBox()
        Me.BatchGet = New System.Windows.Forms.Button()
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()
        Me.VaultsLabel.AutoSize = True
        Me.VaultsLabel.Location = New System.Drawing.Point(36, 24)
        Me.VaultsLabel.Name = "VaultsLabel"
        Me.VaultsLabel.Size = New System.Drawing.Size(91, 13)
        Me.VaultsLabel.TabIndex = 0
        Me.VaultsLabel.Text = "Select vault view:"
        Me.VaultsComboBox.FormattingEnabled = True
        Me.VaultsComboBox.Location = New System.Drawing.Point(39, 40)
        Me.VaultsComboBox.Name = "VaultsComboBox"
        Me.VaultsComboBox.Size = New System.Drawing.Size(121, 21)
        Me.VaultsComboBox.TabIndex = 1
        Me.SelectFiles.Location = New System.Drawing.Point(39, 85)
        Me.SelectFiles.Name = "SelectFiles"
        Me.SelectFiles.Size = New System.Drawing.Size(191, 23)
        Me.SelectFiles.TabIndex = 2
        Me.SelectFiles.Text = "Select files to check out from vault..."
        Me.SelectFiles.UseVisualStyleBackColor = True
        Me.File1List.FormattingEnabled = True
        Me.File1List.HorizontalScrollbar = True
        Me.File1List.Location = New System.Drawing.Point(40, 114)
        Me.File1List.Name = "File1List"
        Me.File1List.SelectionMode = System.Windows.Forms.SelectionMode.MultiExtended
        Me.File1List.Size = New System.Drawing.Size(220, 43)
        Me.File1List.TabIndex = 4
        Me.BatchGet.Location = New System.Drawing.Point(40, 183)
        Me.BatchGet.Name = "BatchGet"
        Me.BatchGet.Size = New System.Drawing.Size(157, 23)
        Me.BatchGet.TabIndex = 6
        Me.BatchGet.Text = "Check out files from vault"
        Me.BatchGet.UseVisualStyleBackColor = True
        Me.OpenFileDialog1.FileName = "OpenFileDialog1"
        Me.OpenFileDialog1.Multiselect = True
        Me.OpenFileDialog1.Title = "Select File"
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(284, 235)
        Me.Name = "Form1"
        Me.Text = "Check Out Files"
    End Sub
    Friend WithEvents VaultsLabel As System.Windows.Forms.Label
    Friend WithEvents VaultsComboBox As System.Windows.Forms.ComboBox
    Friend WithEvents SelectFiles As System.Windows.Forms.Button
    Friend WithEvents File1List As System.Windows.Forms.ListBox
    Friend WithEvents BatchGet As System.Windows.Forms.Button
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
End Class





Back to top

Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

Subject:   Feedback on Help Topics
Page:   Batch Check Out Files Example (VB.NET)
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:


We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again

Web Help Content Version: API Help (English only) 2014 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.