views:

852

answers:

3

I need to create a simple folder in a document library in SharePoint, but I can't seem to find a scrap of documentation on the subject.

The dws webservice seems to be used to create physical folders in a workspace, I need a way to create a folder in a document library.

Not sure what to do , please help

+1  A: 

I found this method to work :

    HttpWebRequest request = (System.Net.HttpWebRequest)HttpWebRequest.Create("http://mySite/MyList/MyfolderIwantedtocreate");
    request.Credentials = CredentialCache.DefaultCredentials;
    request.Method = "MKCOL";
    HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
    response.Close();
JL
A: 

I've done some work with the Web services but I can't find any code that creates a folder. However, I have code that copies files from a network share to an existing folder in a SharePoint document library using UNC paths. It uses System.IO.File - perhaps you could use that technique to create a folder?

Mayo
A: 

I know this is a pretty old question, but in case someone else finds it, this is how I've done it:

       String CAML =  "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
            "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
            "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"&gt;" +
        "<soap:Body>" +
        "<CreateFolder " + "xmlns=\"http://schemas.microsoft.com/sharepoint/soap/dws/\"&gt;"+
            "<url>" + ParentFolder+'/'+NewFolderName+ "</url>"+
        "</CreateFolder>"+
        "</soap:Body>" +
        "</soap:Envelope>";

       String uri = "http://[your site]/_vti_bin/dws.asmx";

       WebClient client = new WebClient();
        client.Headers["SOAPAction"] = "http://schemas.microsoft.com/sharepoint/soap/dws/CreateFolder";
        client.Headers["content-type"] = "text/xml; charset=utf-8";
        client.Encoding = Encoding.UTF8;
        client.UploadStringCompleted += UploadStringCompleted;
        try
        {
            client.UploadStringAsync(new Uri(uri, UriKind.Absolute), "POST", CAML);
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error in upload string async: " + ex.Message);
        }

I was using silverlight, which is why I used upload string async, but this can be done other ways with the same http post method

pclem12