locked
How to create Folder and subFolder using web services RRS feed

  • Question

  • Hi,

    Today I've been working with some Share Point develompment but the truth is that I can't just get it.
    Can any body help me with some easy links to start Share Point Development?
    Here is wath I'm trying: I need to create a new folder (lets say Folder1) inside a Document library. After Folder1 is created, I need to create a new Folder inside Folder1 (lets say Folder1.1) and so on.
    Until now, I'm able to create Folder1 but after that I don't know how to continue creating subfolders.

    It's important to say that I would like to solve this problem by using webservices and let de Microsoft.Sharepoint.dll as just in case.

    I hope somebody help me.

    Thanks.
    • Edited by Mike Walsh FIN Friday, January 15, 2010 4:50 AM using web services added to Title. Include this kind of info in the Title when it's the only thing you are prepared to consider (as you wrote)
    Thursday, January 14, 2010 10:58 PM

Answers

  • You can create folders and subfolders using the Lists web service using the UpdateListItems method. The following example code takes a foldername argument and creates a folder in the root folder of the list. If you want to create a folder within another folder then just change the RootFolder attribute to the url of the folder. Hope this helped.

    http://msdn.microsoft.com/en-us/library/lists.aspx

    public static void UpdateListItemCreateFolder(string folderName)
    {
                listservice.Lists listProxy = new listservice.Lists();
    
                string xmlconst = "<Batch OnError='Continue' RootFolder='http://basesmcdev2/sites/tester1/tester2'><Method ID='1' Cmd='New'><Field Name='ID'>New</Field><Field Name='FSObjType'>1</Field><Field Name='BaseName'>!@foldername</Field></Method></Batch>";
    
    
                listProxy.Url = "http://basesmcdev2/sites/tester1/_vti_bin/lists.asmx";
                listProxy.UseDefaultCredentials = true;
    
             
                XmlDocument doc = new XmlDocument();
                string xmlFolder = xmlconst.Replace("!@foldername", folderName);
                doc.LoadXml(xmlFolder);
                XmlNode batchNode = doc.SelectSingleNode("//Batch");
                XmlNode resultNode = listProxy.UpdateListItems("tester2", batchNode);
    
           
    }

    certdev.com
    • Marked as answer by Ricardo Barona Friday, January 15, 2010 10:43 PM
    Friday, January 15, 2010 3:13 PM

All replies

  • Hi,

    You can use SharePoint built-in Document Workspace Service (DWS.asmx) to add folder in document library. The following link may help you finding methods in the web services.

    http://msdn.microsoft.com/en-us/library/ms774590%28classic%29.aspx
    Thanks,
    Sohel Rana
    http://ranaictiu-technicalblog.blogspot.com
    Friday, January 15, 2010 7:10 AM
  • Hi,

    Are you using a Document WorkSpace template for your sharepoint site?

    If so, you can use the http://servername/_vti_bin/dws.asmx web service.

    The DWS class has some useful methods for managing Documents, Folders, etc

    For creating folders it has a CreateFolder method.


    Madhu
    Friday, January 15, 2010 7:27 AM
  • You can create folders and subfolders using the Lists web service using the UpdateListItems method. The following example code takes a foldername argument and creates a folder in the root folder of the list. If you want to create a folder within another folder then just change the RootFolder attribute to the url of the folder. Hope this helped.

    http://msdn.microsoft.com/en-us/library/lists.aspx

    public static void UpdateListItemCreateFolder(string folderName)
    {
                listservice.Lists listProxy = new listservice.Lists();
    
                string xmlconst = "<Batch OnError='Continue' RootFolder='http://basesmcdev2/sites/tester1/tester2'><Method ID='1' Cmd='New'><Field Name='ID'>New</Field><Field Name='FSObjType'>1</Field><Field Name='BaseName'>!@foldername</Field></Method></Batch>";
    
    
                listProxy.Url = "http://basesmcdev2/sites/tester1/_vti_bin/lists.asmx";
                listProxy.UseDefaultCredentials = true;
    
             
                XmlDocument doc = new XmlDocument();
                string xmlFolder = xmlconst.Replace("!@foldername", folderName);
                doc.LoadXml(xmlFolder);
                XmlNode batchNode = doc.SelectSingleNode("//Batch");
                XmlNode resultNode = listProxy.UpdateListItems("tester2", batchNode);
    
           
    }

    certdev.com
    • Marked as answer by Ricardo Barona Friday, January 15, 2010 10:43 PM
    Friday, January 15, 2010 3:13 PM
  • Guys,

    Thanks to all your answers. I'll be trying each one of them today and will let you know my results.
    Thanks Mike for edit my Title.
    Friday, January 15, 2010 3:33 PM
  • Hi Steve,

    I need to create a folder structure(e.g folder1/folder2) by the running the program once.I tried calling the UpdateListItemCreateFolder recursively and passed an extra rootFolder parameter.I changed the RootFolder attribute as shown below but the code isnt working.Please let me know the right procedure to create a folder structure in a list.

     

     public
    
     
    
    
    static void UpdateListItemCreateFolder(string folderName, string rootFolder) 
    {
    
    ListService.
    
    
    Lists listProxy = new ListService.Lists(); 
     
    
    
    string location = "http://localhost:414/Documents/one" + rootFolder.ToString(); 
     
    
    
    string xmlconst = "<Batch OnError='Continue' RootFolder='" + location.ToString() + "'><Method ID='1' Cmd='New'><Field Name='ID'>New</Field><Field Name='FSObjType'>1</Field><Field Name='BaseName'>!@foldername</Field></Method></Batch>"; 
    listProxy.Url =
    
    
    "http://localhost:414/_vti_bin/lists.asmx"; 
    listProxy.UseDefaultCredentials =
    
    
    true; 
     
    
    
    XmlDocument doc = new XmlDocument(); 
    xmlconst.Replace(
    
    
    "!@root", location); 
     
    
    
    string xmlFolder = xmlconst.Replace("!@foldername", folderName); 
    doc.LoadXml(xmlFolder);
    
     
    
    
    XmlNode batchNode = doc.SelectSingleNode("//Batch"); 
     
    
    
    XmlNode resultNode = listProxy.UpdateListItems("Documents", batchNode); 
    }
    
    
    

    Tuesday, March 9, 2010 12:06 PM
  • string location = "http://localhost:414/Documents/one" + rootFolder.ToString();

    Make sure either the rootFolder includes a beginning forward slash, like "/rootfoldername".

    Also if you are making deeply nested folders the rootFolder name must be the full path of the parent folder like "/rootfoldername/folder1/folder2"
    certdev.com
    • Proposed as answer by PriyeshPPB Wednesday, December 19, 2012 10:05 AM
    Tuesday, March 9, 2010 4:45 PM
  • Hi Steve

    I tried running the above sample code, but I'm getting SoapServerException while calling the lists.UpdateListItems. The exception details says "Guid should contain 32 digits with 4 dashes"

    Does that mean I need to specify the Guid for the new folder or something else is missing.

    Thanks

    Abhijit

    Friday, May 31, 2013 5:33 AM
  • Hi Ricardo.

    I'm using CRM 2013 ONLINE and sharepoint online and i'm trying

    to create 6 subfolders automatically for each record, after the record folder is created..

    Can you help me?

    Monday, May 12, 2014 11:30 AM