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

Question

Question

SDK Question

asked on September 21, 2018 Show version history

Our company has used Laserfiche for many years and have recently purchased the SDK so we can automate some processes in our daily workflow to improve some of our efficiencies. I decided to familiarize myself with the SDK by creating a sample Microsoft windows form app using VS2017 in the C# language. I started with a simple search by adding textbox, button and a listview controls to the form and seems to work great. I wanted to narrow the search down by changing the search path but there seems as though there is no FolderBrowserDialog control in the Laserfiche API that I can find. Does anyone know if there is one for this API or do I need to create a custom control? We are using Laserfiche version 8.3.2.755.

 

Here is a screenshot of the form I created. I would like to be able to click the "Folder Browser" button to populate the textbox next to the button so the user will know what path he/she is searching in.

 

0 0

Replies

replied on September 21, 2018

There is not a folder browser control included in the SDK.  You can see RA LF Folder Picker (VB.NET) to see sample VB code of a quick folder browser/picker I created and shared in 2014.

1 0
replied on September 24, 2018 Show version history

Here is what I use:

I add a 2nd form to the project and add 2 panels, 2 buttons, 1 Treeview, and 1 ImageList (not shown).  To the ImageList, I add an open folder icon and then a folder icon and I point the TreeView ImageList property to the added ImageList.

Here is the code for the folder browser:

    public partial class LFFolderBrowser : Form
    {

        #region Property definition
        // *********************************
        // *********************************
        // **Public Properties for Browser**
        // *********************************
        // *********************************

        private int _EntryId;
        public int EntryId
        {
            get
            {
                return _EntryId;
            }
        }

        private string _Path;
        public string Path
        {
            get
            {
                return _Path;
            }
        }

        // **********************************
        // **********************************
        // **Private Properties for Browser**
        // **********************************
        // **********************************

        private Session _RASession = null;
        private Session RASession
        {
            get
            {
                return _RASession;
            }
            set
            {
                _RASession = value;
            }
        }

        #endregion

        #region LF Log In/Out definition

        private void LFLogout()
        {
            // Only process if LFDatabase object is not nothing 
            if ((RASession != null))
            {
                try
                {
                    // Log Out 
                    RASession.LogOut();
                    RASession.Discard();
                }
                catch (Exception ex)
                {
                    // Log Errors Here 

                }
                // Ensure LFDatabse object is nothing 
                RASession = null;
            }
        }

        private void LFLogin(string sServer, string sRepo, bool bWinAuth, bool bSSL, int SSLPort, string sUser = "admin", string sPW = "")
        {
            // Only process if LFDatabase object is nothing 
            if (RASession == null)
            {
                try
                {
                    // Create LFServer object for server 
                    Server lfserv = new Server(sServer);
                    // Set LFRepository object 
                    RepositoryRegistration LFRepo = new RepositoryRegistration(lfserv, sRepo);
                    RASession = new Session();
                    RASession.ApplicationName = Application.ProductName;
                    // Process Authentication 
                    if (bWinAuth)
                    {
                        // Use blank User and Password for WinAuth 
                        RASession.LogIn(LFRepo);
                    }
                    else
                    {
                        //Do not use empty user name for LF Auth (if that is what was passed) 
                        if (string.IsNullOrEmpty(sUser))
                        {
                            // Try using admin with blank password 
                            sUser = "admin";
                            sPW = "";
                        }
                        RASession.LogIn(sUser, sPW, LFRepo);
                    }
                }
                catch (Exception ex)
                {
                    // Log Errors Here 
                    MessageBox.Show(ex.Message);
                    // Ensure Session object is nothing 
                    RASession = null;
                }
            }
        }

        private void CloudLogin(string customerId, string username, string password)
        {
            if (RASession == null)
            {
                CloudTicket ticket = getCloudTicket(customerId, username, password);
                if (ticket != null)
                {
                    string repositoryName = getCloudRepositoryName(ticket) + ".laserfiche.com";
                    RepositoryRegistration repoReg = new RepositoryRegistration(repositoryName, repositoryName, 80, 443);
                    RASession = new Session();
                    RASession.IsSecure = true;
                    RASession.LogIn(username, password, repoReg);
                }
            }
        }

        private CloudTicket getCloudTicket(string customerId, string username, string password)
        {
            CloudTicket CurrentTicket = null;
            try
            {
                CloudTicketRequestSettings ctrSettings = new CloudTicketRequestSettings();
                ctrSettings.AccountId = customerId;
                ctrSettings.UserName = username;
                ctrSettings.Password = password;
                CurrentTicket = CloudTicket.GetTicket(ctrSettings);
            }
            catch (Exception ex)
            {
                CurrentTicket = null;
            }

            return CurrentTicket;
        }

        private string getCloudRepositoryName(CloudTicket ticket)
        {
            string samlTokenXml = ticket.GetSamlToken();
            string repositoryName = "";
            using (XmlReader reader = XmlReader.Create(new StringReader(samlTokenXml)))
            {
                while (reader.Read())
                {
                    if (reader.LocalName == "Attribute" && reader.GetAttribute("Name") == "http://laserfiche.com/identity/claims/catalyst/roles")
                    {
                        int depth = reader.Depth;
                        while (reader.Read() && reader.Depth > depth)
                        {
                            if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "AttributeValue")
                            {
                                reader.Read();

                                string roleValue = reader.Value;
                                if (!string.IsNullOrEmpty(roleValue) && roleValue.Contains(":"))
                                {
                                    int colonPos = roleValue.IndexOf(":");
                                    string roleDomain = roleValue.Substring(0, colonPos);
                                    string role = roleValue.Substring(colonPos + 1);

                                    if (role == "CreateSession")
                                        repositoryName = roleDomain;
                                }
                            }
                        }
                    }
                }
            }
            return repositoryName;
        }

        #endregion

        // Create new Browser with Cloud Login
        public LFFolderBrowser(string customerId, string username, string password)
        {
            InitializeComponent();
            CloudLogin(customerId, username, password);
            if (RASession == null)
            {
                MessageBox.Show("Log in failed. Please correct problem and try again.");
                this.Dispose();
            }
        }

        // Create new Browser with On Prem Login
        public LFFolderBrowser(string sServer, string sRepo, bool bWinAuth, bool bSSL, int SSLPort, string sUser = "admin", string sPW = "")
        {
            InitializeComponent();
            LFLogin(sServer, sRepo, bWinAuth, bSSL, SSLPort, sUser, sPW);
            if (RASession == null)
            {
                MessageBox.Show("Log in failed. Please correct problem and try again.");
                this.Dispose();
            }
        }

        private void LFFolderBrowser_Load(object sender, EventArgs e)
        {
            // Dock treeview into panel
            tvFolderTree.Dock = DockStyle.Fill;
            // Make sure there is a connection to the repository
            if (RASession == null)
            {
                // No connection
                MessageBox.Show("Log in failed. Please correct problem and try again.");
                this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
                this.Close();
            }
            else
            {
                // Create new Node
                TreeNode RootTreeNode = new TreeNode();
                // Set the treeview imagekey
                RootTreeNode.ImageKey = "Folder";
                // Set Node Text
                RootTreeNode.Text = RASession.Repository.Name;
                // Make new Node expandable
                RootTreeNode.Nodes.Add("");
                // Add new Node to TreeView
                tvFolderTree.Nodes.Add(RootTreeNode);
                // Expand new Node
                tvFolderTree.Nodes[0].Expand();
            }
        }

        private void LFFolderBrowser_FormClosed(object sender, FormClosedEventArgs e)
        {
            LFLogout();
        }

        private void tvFolderTree_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            // Clear any existing child nodes
            e.Node.Nodes.Clear();
            // Get full path from node
            string sFullPath = e.Node.FullPath;
            // Remove repository name from path for LF use
            if (sFullPath.Contains("\\"))
            {
                sFullPath = sFullPath.Replace(sFullPath.Substring(0, sFullPath.IndexOf("\\")), "");
            }
            else
            {
                sFullPath = "\\";
            }
            try
            {
                // Create FolderInfo object fron Node path
                using (FolderInfo LFFolder = Folder.GetFolderInfo(sFullPath, RASession))
                {
                    // configure which columns to retrieve
                    EntryListingSettings entrySetting = 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 (FolderListing listing = LFFolder.OpenFolderListing(entrySetting, 1000))
                    {
                        // the listing is 1-based, 
                        int rowCount = listing.RowsCount;
                        for (int i = 1; i <= rowCount; i++)
                        {
                            // Process only folders
                            // Listing should never get anything other than folder, but will check anyway
                            if (listing.GetDatumAsString(i, SystemColumn.EntryType).ToLower() == "folder")
                            {
                                // Create new Node
                                TreeNode NewTreeNode = new TreeNode();
                                // Set the treeview imagekey
                                NewTreeNode.ImageKey = "Folder";
                                // 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);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                // Log Errors here
            }
        }

        private void tvFolderTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            // Get full path from node
            string sFullPath = e.Node.FullPath;
            // Remove repository name from path for LF use
            if (sFullPath.Contains("\\"))
            {
                sFullPath = sFullPath.Replace(sFullPath.Substring(0, sFullPath.IndexOf("\\")), "");
            }
            else
            {
                sFullPath = "\\";
            }
            try
            {
                // Create FolderInfo object fron Node path
                using (FolderInfo LFFolder = Folder.GetFolderInfo(sFullPath, RASession))
                {
                    // Get Entry ID of selected Node
                    _EntryId = LFFolder.Id;
                    // Get full path of folder
                    _Path = LFFolder.Path;
                }
            }
            catch (Exception ex)
            {
                // Log errors here
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(_Path))
            {
                _Path = "\\";
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Close();
        }
    }

On my main form, I have a Textbox for the LF folder path and a button to open the LF Folder Browser form.

The code I use in the picker button is:

        private void btnLFFolderPicker_Click(object sender, EventArgs e)
        {
            // iLoginType Values
            //    1 = Cloud
            //    0 = On Prem
            switch (iLoginType)
            {
                case 1:
                    LFFolderBrowser lfbCloud = new LFFolderBrowser(sCloudAccountID, sCloudUserName, sCloudPassword);
                    if (lfbCloud.IsDisposed == false)
                    {
                        if (lfbCloud.ShowDialog() == DialogResult.OK)
                        {
                            tbLFPath.Text = lfbCloud.Path;
                        }
                        if (lfbCloud.IsDisposed == false)
                        {
                            lfbCloud.Dispose();
                        }
                    }
                    break;
                default:
                    LFFolderBrowser lfb = new LFFolderBrowser(sServerName, sRepositoryName, bWinAuth, bUseSSL, iSSLPort, sUserName, sPassword);
                    if (lfb.IsDisposed == false)
                    {
                        if (lfb.ShowDialog() == DialogResult.OK)
                        {
                            tbLFPath.Text = lfb.Path;
                        }
                        if (lfb.IsDisposed == false)
                        {
                            lfb.Dispose();
                        }
                    }
                    break;
            }

 

1 0
replied on September 22, 2018

I was admiring this yesterday after I posted this question. Nice piece of work. You wouldn't happen to have this converted over to C# by any chance, would you?blush

0 0
replied on September 23, 2018

Steve,

Any time I need to convert to and from C# I use the Telerik website...

http://converter.telerik.com/

1 0
replied on September 24, 2018

Cliff, Thanks! This will speed up the conversion for sure. Only have a few issues to debug from the conversion. Hopefully, we can get a good result. I'll post the converted code once I finish it.

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

Sign in to reply to this post.