Click here to Skip to main content
15,882,114 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We need to create a folder in WebDAV using the URL.
We have created a folder in server and mapped it to a network drive. Also we have created a website for the folder and enabled directory browsing.

C#
httpWebRequest = (HttpWebRequest)WebRequest.CreateDefault(uri);
            
            
            // Set Credentials
            httpWebRequest.Credentials = CredentialCache.DefaultCredentials;

            // Define the HTTP method.
            //httpWebRequest.Method = C_VERB_FOLDERCREATE;
            httpWebRequest.Method = "MKCOL";

            // Retrieve the response.
            HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();


but the httpWebResponse.status is returned as OK, the above code should return the status as httpWebResponse.Status as "Created" and create a folder designated to webdav folder for us.

Any help is appreciated.

Thanks
Sharath

What I have tried:

C#
httpWebRequest = (HttpWebRequest)WebRequest.CreateDefault(uri);
            
            
            // Set Credentials
            httpWebRequest.Credentials = CredentialCache.DefaultCredentials;

            // Define the HTTP method.
            //httpWebRequest.Method = C_VERB_FOLDERCREATE;
            httpWebRequest.Method = "MKCOL";

            // Retrieve the response.
            HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
Posted
Updated 8-Aug-16 23:37pm
Comments
Tomas Takac 26-Jul-16 17:06pm    
I don't get it. Did it create the folder or not? We are using webdav with sharepoint and I'm pretty sure it returns OK as result. What's the problem?
Member 10017569 26-Jul-16 23:36pm    
It has not created any folder which was expected.

1 solution

you can use,

C#
Server.MapPath(string  path)



to map files on server.
this method worked for me..

for creating folder use this technique,

add this at beginning,

C#
using System.IO;


to create folder on server use following,

C#
string directoryPath = Server.MapPath("~/WebDAV"); //place your path here
    if (!Directory.Exists(directoryPath))
    {
        Directory.CreateDirectory(directoryPath);
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900