Thursday, May 22, 2014

Creating Libraries in SharePoint programmatically / Creating libraries in SharePoint using code

public static void createLibrary()
        {
            string libraryName = "Test";
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite osite = newSPSite("http://myserver02:7676/abc"))
                    {
                        using (SPWeb oweb = osite.OpenWeb())
                        {
                            Guid listGuid = oweb.Lists.Add(libraryName,string.Empty, SPListTemplateType.DocumentLibrary);//SPListTemplateType.Will provide you all templates which can be created
 
                           
                            SPList documentLibrary = oweb.Lists[listGuid];
 
                            documentLibrary.ContentTypesEnabled = true;
                            documentLibrary.OnQuickLaunch = true;
 
                            Console.WriteLine("Library created");
                            Console.ReadLine();
                               
 
 
 
                        }
                    }
                });
 
            }
 
            catch (Exception ex)
            {
                throw ex;
            }
 
 
 
        }


Result 












No comments:

Post a Comment