Wednesday 5 March 2014

Folder Creation in SharePoint 2010 Document Library

I have used the following code for folder creation only in document library via list item creation workflow
SPListItem CurItem = workflowProperties.Item;
SPSite MySite = new SPSite(workflowProperties.WebUrl);
SPWeb Myweb = MySite.OpenWeb();

SPDocumentLibrary spdoclibrary = (SPDocumentLibrary)Myweb.Lists["My Documents"];
Myweb.Folders.Add(workflowProperties.WebUrl + "/My%20Documents/" + CurItem["Title"].ToString());

spdoclibrary.Update();  

Another Way:-
SPList splstDoc = Myweb.Lists["My Documents"];
SPFolderCollection folderColl = splstDoc.RootFolder.SubFolders;
SPFolder newFolder = folderColl.Add(workflowProperties.WebUrl + "/My%20Documents/" + CurItem["Title"].ToString());        

I have used the following code for file along with properties creation in document library via list item creation workflow

Hashtable objhash = new Hashtable();
byte[] byt = new byte[Convert.ToInt32(FileUpload1.PostedFile.ContentLength)];
objhash.Add("custom field name", "value");
SPFolder myfolder = Myweb.GetList(workflowProperties.WebUrl + "/My%20Documents/").RootFolder;
myfolder.Files.Add("Test.txt", byt, objhash, false);           
myfolder.Update();


I have used the following code for folder along with properties creation in document library via list item creation workflow

SPFolder myfolder = Myweb.GetFolder(workflowProperties.WebUrl + "/My%20Documents/");
SPFolder spfolder = myfolder.SubFolders.Add(workflowProperties.WebUrl + "/My%20Documents/" + CurItem["Title"].ToString());
spfolder.Item["Title"] = "Aasai";
spfolder.Item["Test"] = "Aasai";
spfolder.Item.SystemUpdate(false);


8 comments:

  1. Thanks for Information Microsoft SharePoint is a Web application platform developed by Microsoft. The web tools which are designed for the purpose of non-technical users so they can easily Use them. SharePoint can be used to provide intranet portals, document and file management, collaboration, social networks, extranets, websites, enterprise search and business intelligence. It also offers system integration, process integration and workflow automation capabilities. Sharepoint Online Training

    ReplyDelete
  2. Great and really helpful article! Adding to the conversation, providing more information, or expressing a new point of view...Nice information and updates. Really i like it and everyday am visiting your site..
    Sharepoint Training in Chennai

    ReplyDelete
  3. sharepoint service @ desss.com at low cost

    ReplyDelete
  4. Folder Creation in SharePoint 2010 Document Library

    Very informative post...

    SharePoint Web Development

    SharePoint Development Services

    ReplyDelete