使用C#在webdav中创建一个文件夹 [英] Create a folder in webdav using C#

查看:435
本文介绍了使用C#在webdav中创建一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要使用URL在WebDAV中创建一个文件夹。

我们在服务器中创建了一个文件夹并将其映射到网络驱动器。我们还创建了一个文件夹和启用目录浏览的网站。



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.

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





但是httpWebResponse.status返回OK,上面的代码应该返回httpWebResponse的状态.Status为Created并为我们创建一个指定给webdav文件夹的文件夹。



任何帮助表示赞赏。



谢谢

Sharath



我的尝试:





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:

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

推荐答案

你可以使用,



you can use,

Server.MapPath(string  path)







来映射服务器上的文件。

这个方法对我有用..



for创建文件夹使用这种技术,



在开头添加这个,






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

for creating folder use this technique,

add this at beginning,

using System.IO;





在服务器上创建文件夹使用如下,




to create folder on server use following,

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


这篇关于使用C#在webdav中创建一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆