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);


5 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. It is really a great and useful piece of info. I’m glad that you shared this helpful info with us. Please keep us informed like this. Thank you for sharing.

    Back to Original Services Private Limited

    ReplyDelete
  4. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.
    Isoft Innovations Adyar
    Isoft Innovations Facebook

    ReplyDelete
  5. I am regular visitor of this blog .I am working as blog reviewer in a private press and I saw many useful posts here. Sure, I will give best ratings for this blog .Keep posting best posts like this to get top reviews and ratings from blog reviewers and people .And I am thankful for this valuable post.
    Nautical Science Colleges in Chennai | Mechanical Colleges in Chennai | ECE Colleges in Chennai

    ReplyDelete