You are viewing limited content. For full access, please sign in.

Question

Question

RA LF Folder Picker (VB.NET)

asked on February 6, 2014

 I have shared a folder picker in the past based on LFSO.  Here I will share an RA based folder browser/picker.

In your VB project, add an new Dialog item (I named mine PFTBrowser).  Add a Panel (its name does not matter) to the Dialog form and set it to cover most of the form.  Now place a TreeView object anywhere inside the panel and name it tvFolderTree.

 

Here is the code for the PFTBrowse Dialog form:

'***********************************************************
'***********************************************************
'**               PFTBrowser by Bert Warren               **
'**         Copyright © Paper Free Technology 2008        **
'**               Laserfiche Folder Browser               **
'***********************************************************
'***********************************************************

'    PFTBrowser
' This Dialog Window is made up of a panel and treeview for
' displaying the LF Folder structure, and a TableLayoutPanel
' with the OK & Cancel buttons.
' To use this item, instantiate using the keyword New and
' provide valid LF server, repository, windows authentication,
' user name, and password.  This will cause it to create the
' form and log into the repository.  Then when the form is
' closed, it will log out.
'   Usage
'       Dim myBrowser As New PFTBrowser(sLFServerName, sLFRepositoryName, bLFWinAuth, sLFUserName, sLFPassword)
'       'Open/Show new PFTBrowser Dialog
'       myBrowser.ShowDialog()
'       ' Check dialog result
'       If myBrowser.DialogResult = Windows.Forms.DialogResult.OK Then
'       'If OK was clicked, set _Path = to selected folder path
'       'and/or _EntryID = to selected folder Entry ID
'           Dim _Path As String = myBrowser.Path
'           Dim _EntryID As Integer = myBrowser.EntryId
'       End If
'       ' Cleanup
'       myBrowser = Nothing

Imports System.Windows.Forms
Imports Laserfiche.RepositoryAccess

Public Class PFTBrowser

    Private myLFSession As Session = Nothing

    '*********************************
    '*********************************
#Region "Public Properties for Browser"
    Private _EntryId As Integer
    Public ReadOnly Property EntryId() As Integer
        Get
            Return _EntryId
        End Get
    End Property

    Private _Path As String
    Public ReadOnly Property Path() As String
        Get
            Return _Path
        End Get
    End Property

    Private _sServerName As String
    Public WriteOnly Property LFServerName() As String
        Set(value As String)
            _sServerName = value
        End Set
    End Property

    Private _sRepositoryName As String
    Public WriteOnly Property LFRepositoryName() As String
        Set(value As String)
            _sRepositoryName = value
        End Set
    End Property

    Private _sUserName As String
    Public WriteOnly Property LFUserName() As String
        Set(value As String)
            _sUserName = value
        End Set
    End Property

    Private _sPassword As String
    Public WriteOnly Property LFPassword() As String
        Set(value As String)
            _sPassword = value
        End Set
    End Property

    Private _bWinAuth As Boolean
    Public WriteOnly Property bLFWinAuth() As Boolean
        Set(value As Boolean)
            _bWinAuth = value
        End Set
    End Property

#End Region
    '*********************************
    '*********************************
#Region "Private LF Log In/Out"

    Private Sub LFLogout()
        ' Only process if LFDatabase object is not nothing 
        If (myLFSession IsNot Nothing) Then
            Try
                ' Log Out 
                myLFSession.LogOut()
                myLFSession.Discard()
                ' Log Errors Here 

            Catch ex As Exception
            End Try
            ' Ensure LFDatabse object is nothing 
            myLFSession = Nothing
        End If
    End Sub

    Private Sub LFLogin(sServer As String, sRepo As String, bWinAuth As Boolean, Optional sUser As String = "admin", Optional sPW As String = "")
        ' Only process if LFDatabase object is nothing 
        If myLFSession Is Nothing Then
            Try
                ' Create LFServer object for server 
                Dim lfserv As New Server(sServer)
                ' Set LFRepository object 
                Dim LFRepo As New RepositoryRegistration(lfserv, sRepo)
                myLFSession = New Session()
                myLFSession.ApplicationName = Application.ProductName
                ' Process Authentication 
                If bWinAuth Then
                    ' Use blank User and Password for WinAuth 
                    myLFSession.LogIn(LFRepo)
                Else
                    'Do not use empty user name for LF Auth (if that is what was passed) 
                    If String.IsNullOrEmpty(sUser) Then
                        ' Try using admin with blank password 
                        sUser = "admin"
                        sPW = ""
                    End If
                    myLFSession.LogIn(sUser, sPW, LFRepo)
                End If
            Catch ex As Exception
                ' Log Errors Here 
                MessageBox.Show(ex.Message)
                ' Ensure Session object is nothing 
                myLFSession = Nothing
            End Try
        End If
    End Sub

#End Region
    '*********************************
    '*********************************
#Region "Private Subs & Functions"

    Private Sub InitTV()
        ' Create new Node
        Dim RootTreeNode As New TreeNode
        ' Set Node Text = Repository name
        RootTreeNode.Text = myLFSession.Repository.Name
        ' Make new Node expandable
        RootTreeNode.Nodes.Add("")
        ' Add new Node to TreeView
        tvFolderTree.Nodes.Add(RootTreeNode)
        ' Expand new Node
        tvFolderTree.Nodes.Item(0).Expand()
    End Sub

    Private Sub tvFolderTree_AfterExpand(sender As System.Object, e As System.Windows.Forms.TreeViewEventArgs) Handles tvFolderTree.AfterExpand
        ' Clear any existing child nodes
        e.Node.Nodes.Clear()
        ' Get full path from node
        Dim sFullPath As String = e.Node.FullPath
        ' Remove repository name from path for LF use
        If sFullPath.Contains("\") Then
            sFullPath = sFullPath.Replace(sFullPath.Substring(0, sFullPath.IndexOf("\")), "")
        Else
            sFullPath = "\"
        End If
        Try
            'Create FolderInfo object fron Node path
            Dim LFFold As FolderInfo = Folder.GetFolderInfo(sFullPath, myLFSession)
            ' configure which columns to retrieve
            Dim entrySetting As New EntryListingSettings()
            ' Only get folders
            entrySetting.EntryFilter = EntryTypeFilter.Folders
            ' Include Entry Type
            entrySetting.AddColumn(SystemColumn.EntryType)
            ' Include Entry Name
            entrySetting.AddColumn(SystemColumn.DisplayName)
            ' get the contents of the lf folder
            Using listing As FolderListing = LFFold.OpenFolderListing(entrySetting, 1000)
                ' the listing is 1-based, 
                Dim rowCount As Integer = listing.RowsCount
                For i As Integer = 1 To rowCount
                    ' Process only folders
                    ' Listing should never get anything other than folder, but will check anyway
                    If listing.GetDatumAsString(i, SystemColumn.EntryType).ToLower = "folder" Then
                        ' Create new Node
                        Dim NewTreeNode As New TreeNode
                        ' Set Node Text = folder name
                        NewTreeNode.Text = listing.GetDatumAsString(i, SystemColumn.DisplayName)
                        ' Make new Node expandable
                        NewTreeNode.Nodes.Add("")
                        ' Add new Node to TreeView
                        e.Node.Nodes.Add(NewTreeNode)
                    End If
                Next
            End Using
            ' Cleanup
            LFFold.Dispose()
            LFFold = Nothing
        Catch ex As Exception

        End Try
    End Sub

    Private Sub tvFolderTree_AfterSelect(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewEventArgs) Handles tvFolderTree.AfterSelect
        ' Get full path from node
        Dim sFullPath As String = e.Node.FullPath
        ' Remove repository name from path for LF use
        If sFullPath.Contains("\") Then
            sFullPath = sFullPath.Replace(sFullPath.Substring(0, sFullPath.IndexOf("\")), "")
        Else
            sFullPath = "\"
        End If
        Try
            'Create FolderInfo object from Node path
            Dim LFFold As FolderInfo = Folder.GetFolderInfo(sFullPath, myLFSession)
            ' Get Entry ID of selected Node
            _EntryId = LFFold.Id
            ' Get full path of folder
            _Path = LFFold.Path
            ' Cleanup
            LFFold.Dispose()
            LFFold = Nothing
        Catch ex As Exception

        End Try
    End Sub

#End Region
    '*********************************
    '*********************************
#Region "Button Actions for Browser"

    Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
        Me.DialogResult = System.Windows.Forms.DialogResult.Cancel
        Me.Close()
    End Sub

#End Region
    '*********************************
    '*********************************
#Region "Form Actions for Browser"

    Public Sub New(ByVal LFServerName As String, ByVal LFRepositoryName As String, ByVal UseWindowsAuthentication As Boolean, ByVal LFUserName As String, ByVal LFPassword As String)
        MyBase.New()
        InitializeComponent()
        LFLogin(LFServerName, LFRepositoryName, UseWindowsAuthentication, LFUserName, LFPassword)
    End Sub

    Private Sub PFTBrowser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Make TreeView fill panel1
        Me.tvFolderTree.Dock = DockStyle.Fill
        ' Initialize TreeView
        InitTV()
    End Sub

    Private Sub PFTBrowser_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        ' Cleanup
        LFLogout()
    End Sub

#End Region
    '*********************************
    '*********************************
End Class

 

8 0

Replies

replied on March 16, 2015

What no comments?  Bert, you continue your awesomeness with a whole tutorial on RA and how to navigate it's many objects and nuances. Three thumbs up!

0 0
replied on September 24, 2015

Hi Bert,

You are great! This is just what I needed, I just translated this to C# and it's working, now I just need to find out how to create a document based on the folder picked (on the tree view). 

 

Thank you so much! 

0 0
replied on September 25, 2015 Show version history

See Using RA to create a document, assign a template and populate fields for code sample of how to create a document.

In the code line to get the parent folder object, pass the path or Folder ID that is returned from the picker.

 

EDIT:

You can also look at RA_Demo_Import_VB 2010 project to see how I create LF Folders and Documents.

2 0
replied on September 25, 2015

Thank you! Just what I needed 

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.