Saturday, February 23, 2013

TreeView with the nodes as document library names using Sharepoint2010


In this post we are going to construct a TreeView with the nodes as sharepoint document library names using Sharepoint2010
Root Node will be the Site Url. 

Before we proceed with the code add a treeview with ID as myTreeView to your page. 
Below is the code snippet.

try
            {
                using (SPSite site = new SPSite("<<http://site Url>>"))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        SPListCollection docLibraryColl = web.GetListsOfType(SPBaseType.DocumentLibrary);

                        List<string> docLibrariesList = new List<string>();
                        foreach (SPList list in docLibraryColl)
                        {
                            if (!list.Hidden)
//if you don’t want style library and Forms templates then use below condition instead of above
                            //if (!list.Hidden && list.title != "Style Library" && list.title != "Form Templates")
                            {
                                SPDocumentLibrary doclib = (SPDocumentLibrary)list;
                                string docLibTitle = doclib.Title;
                                int docsCount = doclib.ItemCount;
                                docLibrariesList.Add(docLibTitle);
                            }
                        }

                        TreeNode RootNode = new TreeNode();
                        //Here we are binding the root node as Site Url
   RootNode.Text = "<<http://site url>>";

                        foreach (string docLibrary in docLibrariesList)
                        {
                            TreeNode childNode = new TreeNode();
                            childNode.Text = docLibrary;
                            RootNode.ChildNodes.Add(childNode);
                        }
   // myTreeView is treeview controls ID present on the aspx page
                        myTreeView.Nodes.Add(RootNode);

                    }
                }
            }
            catch (Exception ex)
            {

            }


Hope this helps..

Set this url as default/Home page of your browser


In this post we are going to set any url as default/Home page of your browser.
Recently one of my friend asked me to do this. So thought of sharing with you guys as well.
Consider we are going to set the http://www.google.co.in as the Default/Home page of the browser.

Add a below anchor tag to your webpage
<A style="CURSOR: hand; font-decoration: underline" href="#" onclick="this.style.behavior='url(#default#homepage)';this.setHomePage('http://www.google.co.in');">set as your home page</A>

So when user clicks on this button, a popin will appear asking to set google as the home page.
Just click on Ok. That's it, your browser has been updated with the default/Home page as google.com


Hope this helps...


Popular Posts