Traverse Users and Groups in Vault Example (VB.NET)
This example shows how to traverse the users and groups in
a vault and send a message, also called a notification, to all users in the
vault.
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.
![](UsersAndGroups.gif)
'----------------------------------------------------------------------------
' Preconditions:
' 1. Start Microsoft Visual Studio 2010.
' a. Click File > New > Project > Visual Basic > Windows Forms Application.
' b. Type UsersAndGroups 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. Create a form similar to the form shown above and change:
' 1. Top label to VaultsLabel.
' 2. Combo box to VaultsComboBox.
' 3. Traverse users button to TraverseUsersButton.
' 4. Traverse groups button to TraverseGroupsButton.
' 5. Traverse group members button to TraverseGroupMembersButton.
' 6. Send consultation request button to SendConsultationRequestButton.
' g. Replace the code in Form1.vb with this code.
' h. 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. Click Debug > Start Debugging or press F5.
'
' Postconditions:
' 1. Displays a dialog.
' 2. Select a vault.
' 3. Click Traverse users.
' A message box is displayed showing the users
' in the vault.
' 4. Click OK to close the message box.
' 5. Click Traverse groups.
' A message box is displayed showing the
' the groups in the vault.
' 6. Click OK to close the message box.
' 7. Click Traverse group members.
' A message box is displayed showing the
' the groups, and the users in those groups, in
' the vault.
' 8. Click OK to close the message box.
' 9. Click Send consultation request.
' After several minutes, a SolidWorks Enterprise PDM notification
' is displayed only to logged-in users.
' 10. To open the the message, click:
' * either the notification while it is displayed or
' the SolidWorks Enterprise PDM tray icon.
' - or -
' * Tools > Inbox in Windows Explorer.
' 11. Close the dialog.
'----------------------------------------------------------------------------
'Form1.vb
Imports System.IO
Imports System.Xml.Serialization
Imports EPDM.Interop.epdm
Public Class UsersAndGroups
Private Sub UsersAndGroups_Load(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim vault As IEdmVault8 = New EdmVault5
Dim Views() As EdmViewInfo = {}
vault.GetVaultViews(Views, False)
VaultsComboBox.Items.Clear()
For Each View As EdmViewInfo In Views
VaultsComboBox.Items.Add(View.mbsVaultName)
Next
If VaultsComboBox.Items.Count > 0 Then
VaultsComboBox.Text = VaultsComboBox.Items(0)
End If
End Sub
Private Sub TraverseUsersButton_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles TraverseUsersButton.Click
'Declare and create an instance of IEdmVault5 object
Dim vault As IEdmVault5 = New EdmVault5()
'Log into selected vault as the current user
vault.LoginAuto(VaultsComboBox.Text, _
Me.Handle.ToInt32())
'Declare an IEdmUserMgr5 object
Dim UserMgr As IEdmUserMgr5
'The IEdmUserMgr5 interface is implemented by the
'same class as the IEdmVault5 interface,
'so assign the value of the IEdmVault5 object
UserMgr = vault
Dim Users As String = vbNullString
Dim UserPos As IEdmPos5
UserPos = UserMgr.GetFirstUserPosition()
While Not UserPos.IsNull
Dim User As IEdmUser5
User = UserMgr.GetNextUser(UserPos)
Users = Users + User.Name + vbCrLf
End While
MessageBox.Show(Users, vault.Name + _
" Vault Users", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End Sub
Private Sub TraverseGroupsButton_Click(ByVal sender _
As System.Object, ByVal e As System.EventArgs) _
Handles TraverseGroupsButton.Click
'Declare and create an instance of IEdmVault5 object
Dim vault As IEdmVault5 = New EdmVault5()
'Log into selected vault as the current user
vault.LoginAuto(VaultsComboBox.Text, _
Me.Handle.ToInt32())
'Declare an IEdmUserMgr5 object
Dim UserMgr As IEdmUserMgr5
'The IEdmUserMgr5 interface is implemented by the
'same class as the IEdmVault5 interface,
'so assign the value of the IEdmVault5 object
UserMgr = vault
Dim Groups As String = vbNullString
Dim UserGroupPos As IEdmPos5
UserGroupPos = UserMgr.GetFirstUserGroupPosition()
While Not UserGroupPos.IsNull
Dim UserGroup As IEdmUserGroup5
UserGroup = UserMgr.GetNextUserGroup _
(UserGroupPos)
Groups = Groups + UserGroup.Name + vbCrLf
End While
MessageBox.Show(Groups, vault.Name + _
" Vault Groups", MessageBoxButtons.OK, _
MessageBoxIcon.Information)
End Sub
Private Sub TraverseGroupMembersButton_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles TraverseGroupMembersButton.Click
'Declare and create an instance of IEdmVault5 object
Dim vault As IEdmVault5 = New EdmVault5()
'Log into selected vault as the current user
vault.LoginAuto(VaultsComboBox.Text, _
Me.Handle.ToInt32())
'Declare an IEdmUserMgr5 object
Dim UserMgr As IEdmUserMgr5
'The IEdmUserMgr5 interface is implemented by the
'same class as the IEdmVault5 interface,
'so assign the value of the IEdmVault5 object
UserMgr = vault
Dim Groups As String = vbNullString
Dim UserGroupPos As IEdmPos5
UserGroupPos = UserMgr.GetFirstUserGroupPosition()
While Not UserGroupPos.IsNull
Dim UserGroup As IEdmUserGroup5
UserGroup = UserMgr.GetNextUserGroup _
(UserGroupPos)
Groups = Groups + UserGroup.Name + " Members:" _
+ vbCrLf
Groups = Groups + GetMembers(UserGroup)
End While
MessageBox.Show(Groups, vault.Name + _
" Vault Group Users", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Function GetMembers(ByVal UserGroup _
As IEdmUserGroup5) As String
GetMembers = vbNullString
Dim Users As String = vbNullString
Dim UserPos As IEdmPos5
UserPos = UserGroup.GetFirstUserPosition()
While Not UserPos.IsNull
Dim User As IEdmUser5
User = UserGroup.GetNextUser(UserPos)
Users = Users + " " + User.Name + vbCrLf
End While
GetMembers = Users
End Function
Private Sub SendConsultationRequestButton_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles SendConsultationRequestButton.Click
'Declare and create an instance of IEdmVault5 object
Dim vault As IEdmVault5 = New EdmVault5()
'Log into selected vault as the current user
vault.LoginAuto(VaultsComboBox.Text, _
Me.Handle.ToInt32())
'Declare an IEdmUserMgr5 object
Dim UserMgr As IEdmUserMgr5
'The IEdmUserMgr5 interface is implemented by the
'same class as the IEdmVault5 interface,
'so assign the value of the IEdmVault5 object
UserMgr = vault
Dim UserGroup As IEdmUserGroup5
UserGroup = UserMgr.GetUserGroup("All Users")
If Not UserGroup Is Nothing Then
Dim UserPos As IEdmPos5
UserPos = UserGroup.GetFirstUserPosition()
While Not UserPos.IsNull
Dim User As IEdmUser5
User = UserGroup.GetNextUser(UserPos)
If User.IsLoggedIn Then
User.SendMsg("Informal review request", _
"Please stop by my office sometime " + _
"this morning for a quick informal " + _
"review of my design changes before " + _
"I submit them for approval.")
End If
End While
End If
End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class UsersAndGroups
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)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
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.VaultsComboBox = New System.Windows.Forms.ComboBox()
Me.VaultsLabel = New System.Windows.Forms.Label()
Me.TraverseUsersButton = New System.Windows.Forms.Button()
Me.TraverseGroupsButton = New System.Windows.Forms.Button()
Me.TraverseGroupMembersButton = New System.Windows.Forms.Button()
Me.SendConsultationRequestButton = New System.Windows.Forms.Button()
Me.SuspendLayout()
'
'VaultsComboBox
'
Me.VaultsComboBox.FormattingEnabled = True
Me.VaultsComboBox.Location = New System.Drawing.Point(49, 34)
Me.VaultsComboBox.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.VaultsComboBox.Name = "VaultsComboBox"
Me.VaultsComboBox.Size = New System.Drawing.Size(146, 21)
Me.VaultsComboBox.TabIndex = 10
'
'VaultsLabel
'
Me.VaultsLabel.AutoSize = True
Me.VaultsLabel.Location = New System.Drawing.Point(46, 9)
Me.VaultsLabel.Margin = New System.Windows.Forms.Padding(2, 0, 2, 0)
Me.VaultsLabel.Name = "VaultsLabel"
Me.VaultsLabel.Size = New System.Drawing.Size(91, 13)
Me.VaultsLabel.TabIndex = 11
Me.VaultsLabel.Text = "Select vault view:"
'
'TraverseUsersButton
'
Me.TraverseUsersButton.Location = New System.Drawing.Point(49, 69)
Me.TraverseUsersButton.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.TraverseUsersButton.Name = "TraverseUsersButton"
Me.TraverseUsersButton.Size = New System.Drawing.Size(146, 41)
Me.TraverseUsersButton.TabIndex = 15
Me.TraverseUsersButton.Text = "Traverse users"
Me.TraverseUsersButton.UseVisualStyleBackColor = True
'
'TraverseGroupsButton
'
Me.TraverseGroupsButton.Location = New System.Drawing.Point(49, 126)
Me.TraverseGroupsButton.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.TraverseGroupsButton.Name = "TraverseGroupsButton"
Me.TraverseGroupsButton.Size = New System.Drawing.Size(146, 41)
Me.TraverseGroupsButton.TabIndex = 16
Me.TraverseGroupsButton.Text = "Traverse groups"
Me.TraverseGroupsButton.UseVisualStyleBackColor = True
'
'TraverseGroupMembersButton
'
Me.TraverseGroupMembersButton.Location = New System.Drawing.Point(49, 183)
Me.TraverseGroupMembersButton.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.TraverseGroupMembersButton.Name = "TraverseGroupMembersButton"
Me.TraverseGroupMembersButton.Size = New System.Drawing.Size(146, 41)
Me.TraverseGroupMembersButton.TabIndex = 17
Me.TraverseGroupMembersButton.Text = "Traverse group members"
Me.TraverseGroupMembersButton.UseVisualStyleBackColor = True
'
'SendConsultationRequestButton
'
Me.SendConsultationRequestButton.Location = New System.Drawing.Point(49, 240)
Me.SendConsultationRequestButton.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.SendConsultationRequestButton.Name = "SendConsultationRequestButton"
Me.SendConsultationRequestButton.Size = New System.Drawing.Size(146, 41)
Me.SendConsultationRequestButton.TabIndex = 18
Me.SendConsultationRequestButton.Text = "Send consultation request"
Me.SendConsultationRequestButton.UseVisualStyleBackColor = True
'
'UsersAndGroups
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(291, 317)
Me.Controls.Add(Me.SendConsultationRequestButton)
Me.Controls.Add(Me.TraverseGroupMembersButton)
Me.Controls.Add(Me.TraverseGroupsButton)
Me.Controls.Add(Me.TraverseUsersButton)
Me.Controls.Add(Me.VaultsComboBox)
Me.Controls.Add(Me.VaultsLabel)
Me.Margin = New System.Windows.Forms.Padding(2, 2, 2, 2)
Me.Name = "UsersAndGroups"
Me.Text = "Traverse users and groups"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents VaultsComboBox As System.Windows.Forms.ComboBox
Friend WithEvents VaultsLabel As System.Windows.Forms.Label
Friend WithEvents TraverseUsersButton As System.Windows.Forms.Button
Friend WithEvents TraverseGroupsButton As System.Windows.Forms.Button
Friend WithEvents TraverseGroupMembersButton As System.Windows.Forms.Button
Friend WithEvents SendConsultationRequestButton As System.Windows.Forms.Button
End Class