Thursday, May 22, 2014

Creating folders in SharePoint programmatically / Creating folders in SharePoint using Code

public static void createFolder()
        {
           
            string libraryName = "Test";
            string folderName = "test1";
            string siteUrl = "http://myserver02:7676/abc";
            try
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (SPSite osite = newSPSite("http://myserver02:7676/abc"))
                    {
                        using (SPWeb oweb = osite.OpenWeb())
                        {
                            SPFolderCollection folderCollection = oweb.Folders;
                            string newFolderUrl = siteUrl + "/" + libraryName + "/" + folderName;
 
                            SPFolder newFolder = folderCollection.Add(newFolderUrl);
 
 
                            Console.WriteLine("Folder created");
                            Console.ReadLine();
 
 
 
 
                        }
                    }
                });
 
            }
 
            catch (Exception ex)
            {
                throw ex;
            }
 
 
 
        }


Please note : To create folders using code,the library has to be visible in Quick Lunch bar
               




No comments:

Post a Comment