windows server 2003开启webDAV服务

1、 启动“IIS管理器”选择“WEB服务扩展”,选择“WEBDAV”的允许按钮启动WEBDAV功能

2、建立一个虚拟目录,对应到一个本地目录。

3、启动系统“服务”中的“WebClient”服务

参考网址

WebDAV文档rfc2518    http://www.ietf.org/rfc/rfc2518.txt

webdav常用方法和概念总结   http://blog.csdn.net/mahongming/archive/2007/09/10/1779033.aspx

在C#中通过webdav操作exchange    http://www.cnblogs.com/umlchina/archive/2005/04/25/144768.html

//--------------WebDAV上传代码-----

private void upload()

{
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://10.57.144.2/WebDAV/IMS對外教育訓練PPTnew.pdf");
           
req.Credentials = new NetworkCredential("username",
"password");//用户名,密码   //CredentialCache.DefaultCredentials使用默认的认证
            req.PreAuthenticate = true;
            req.Method = "PUT";
            req.AllowWriteStreamBuffering = true;

// Retrieve request stream
            Stream reqStream = req.GetRequestStream();

// Open the local file
            FileStream rdr = new FileStream("C://IMS對外教育訓練PPTnew.pdf", FileMode.Open);

// Allocate byte buffer to hold file contents
            byte[] inData = new byte[4096];

// loop through the local file reading each data block
            //  and writing to the request stream buffer
            int bytesRead = rdr.Read(inData, 0, inData.Length);
            while (bytesRead > 0)
            {
                reqStream.Write(inData, 0, bytesRead);
                bytesRead = rdr.Read(inData, 0, inData.Length);
            }

rdr.Close();
            reqStream.Close();

req.GetResponse();

//也可以用以下的方式

/*  System.Uri myURi = new System.Uri("http://10.57.144.2/WebDAV/hello.doc");
              FileStream inStream = File.OpenRead("C://timeTest.doc"); 
 
            WebRequest req = WebRequest.Create(myURi);
            req.Method = "PUT";
              req.Timeout = System.Threading.Timeout.Infinite;
 
              req.Credentials = CredentialCache.DefaultCredentials;
              Stream outStream = req.GetRequestStream();
 
              //CopyStream(inStream, outStream);
              byte[] inData = new byte[4096];
              int bytesRead = inStream.Read(inData, 0, inData.Length);
              while (bytesRead > 0)
              {
                  outStream.Write(inData, 0, bytesRead);
                  bytesRead = inStream.Read(inData, 0, inData.Length);
              }
              inStream.Close();
              outStream.Close();
              req.GetResponse();*/

}

//--------------WebDAV下载代码-----

private void WebDAVGet_Click(object sender, EventArgs e)
        {
            System.Uri myURi = new System.Uri(@"http://10.57.144.2/WebDAV/hello.doc");
            string sfilePath = "C://hello.doc";

WebRequest req = WebRequest.Create(myURi);
            req.Method = "GET";
            req.Timeout = System.Threading.Timeout.Infinite;
            req.Credentials = CredentialCache.DefaultCredentials;
            WebResponse res = req.GetResponse();
            Stream inStream = res.GetResponseStream();

FileStream fs = new FileStream(sfilePath, FileMode.OpenOrCreate);

byte[] inData = new byte[4096];
            int bytesRead = inStream.Read(inData, 0, inData.Length);
            while (bytesRead > 0)
            {
                fs.Write(inData, 0, bytesRead);
                bytesRead = inStream.Read(inData, 0, inData.Length);
            }

fs.Close();

inStream.Close();
        }

//--------------WebDAV删除代码-----

private void WebDAVDel_Click(object sender, EventArgs e)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(@"http://10.57.144.2/WebDAV/Powerpoint.pptx");
            //req.Credentials = new NetworkCredential("Administrator", "123456");
            req.PreAuthenticate = true;
            req.Method = "DELETE";
            //req.AllowWriteStreamBuffering = true;

req.GetResponse();
        }

//--------------WebDAV列出文件夹文件列表代码-----

private void WebDAVList_Click(object sender, EventArgs e)
        {
            
            try
            {

MSXML2.XMLHTTP30 oXMLHttp = new MSXML2.XMLHTTP30();    //需要增加Microsoft.XML 6.0  COM

String sUrl = "http://10.57.144.2/WebDAV/";

string strXml;
                strXml = "<?xml version=/"1.0/"?> ";
                strXml += "<d:propfind xmlns:d=/"DAV:/" xmlns:o=/"urn:schemas-microsoft-com:office:office/">";
                strXml += "<d:prop>";
                strXml += "<d:displayname/>";       //名称
                strXml += "<d:getcontentlength/>";    //大小
                strXml += "<d:iscollection/>";     //是否文件夹
                strXml += "<d:getlastmodified/>";   //最后修改时间
                strXml += "</d:prop>";
                strXml += "</d:propfind>";

/*strXml = "<?xml version=/"1.0/" encoding=/"utf-8/" ?>";
                strXml += "<D:propfind xmlns:D=/"DAV:/">";
                strXml += "<D:allprop/>";     //列出所有的属性
                strXml += "</D:propfind>";*/

oXMLHttp.open("PROPFIND", sUrl, false, "administrator", "drm.123");

oXMLHttp.setRequestHeader("Content-Type", "text/xml");
                oXMLHttp.setRequestHeader("Translate", "f");

//Console.WriteLine(sQuery.Length);
                Console.WriteLine(strXml);
                oXMLHttp.send(strXml);

Console.WriteLine(oXMLHttp.status);
                Console.WriteLine(oXMLHttp.statusText);
                File.WriteAllBytes(@"C:/list.xml", Encoding.UTF8.GetBytes(oXMLHttp.responseText));

//对返回的xml文件进行解析,取出所需属性
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(oXMLHttp.responseText);

XmlNode root = doc.DocumentElement;
                System.Collections.IEnumerator ienum = root.GetEnumerator();
                XmlNode book;
                while (ienum.MoveNext())
                {
                    book = (XmlNode)ienum.Current;
                    book = book.ChildNodes[1].ChildNodes[1];
                    System.Collections.IEnumerator ienum2 = book.GetEnumerator();
                    while (ienum2.MoveNext())
                    {
                        XmlNode node = (XmlNode)ienum2.Current;
                        Console.Write(node.InnerXml);
                        Console.Write("-");
                    }
                    //Console.WriteLine(book.OuterXml);
                    //Console.WriteLine(book.InnerXml);
                    Console.WriteLine();
                }

}
            catch (Exception ex)
            {
                Console.WriteLine("{0} Exception caught.", ex);
            }

}

//----新建文件夾----

private void WebDAVNewFolder_Click(object sender, EventArgs e)
        {
            try
            {
                // Create the HttpWebRequest object.
                HttpWebRequest objRequest = (HttpWebRequest)HttpWebRequest.Create(@"http://10.57.144.2/WebDAV/new");
                // Add the network credentials to the request.
                objRequest.Credentials = new NetworkCredential("F3226142", "drm.123");//用户名,密码
                // Specify the method.
                objRequest.Method = "MKCOL";

HttpWebResponse objResponse = (System.Net.HttpWebResponse)objRequest.GetResponse();

// Close the HttpWebResponse object.
                objResponse.Close();

}
            catch (Exception ex)
            {
                throw new Exception("Can't create the foder" + ex.ToString());
            }            
        }

webDAV服务的开启以及客户端的上传、下载、删除、新建文件夾、列表的代码(C#)的更多相关文章

  1. 配置允许匿名用户登录访问vsftpd服务,进行文档的上传下载、文档的新建删除等操作

    centos7环境下 临时关闭防火墙 #systemctl stop firewalld 临时关闭selinux #setenforce 0 安装ftp服务 #yum install vsftpd - ...

  2. Android连接socket服务器上传下载多个文件

    android连接socket服务器上传下载多个文件1.socket服务端SocketServer.java public class SocketServer { ;// 端口号,必须与客户端一致 ...

  3. Python 一键上传下载&一键提交文件到SVN入基线工具

    一键上传下载&一键提交文件到SVN入基线工具   by:授客 QQ:1033553122 实现功能 1 测试环境 1 使用说明 1   注: 根据我司项目规则订制的一套工具,集成以下功能,源码 ...

  4. 使用C#WebClient类访问(上传/下载/删除/列出文件目录)由IIS搭建的http文件服务器

    前言 为什么要写这边博文呢?其实,就是使用C#WebClient类访问由IIS搭建的http文件服务器的问题花了我足足两天的时间,因此,有必要写下自己所学到的,同时,也能让广大的博友学习学习一下. 本 ...

  5. Struts2 文件上传,下载,删除

    本文介绍了: 1.基于表单的文件上传 2.Struts 2 的文件下载 3.Struts2.文件上传 4.使用FileInputStream FileOutputStream文件流来上传 5.使用Fi ...

  6. java 通过sftp服务器上传下载删除文件

    最近做了一个sftp服务器文件下载的功能,mark一下: 首先是一个SftpClientUtil 类,封装了对sftp服务器文件上传.下载.删除的方法 import java.io.File; imp ...

  7. 使用C#WebClient类访问(上传/下载/删除/列出文件目录)

    在使用WebClient类之前,必须先引用System.Net命名空间,文件下载.上传与删除的都是使用异步编程,也可以使用同步编程, 这里以异步编程为例: 1)文件下载: static void Ma ...

  8. java FTP 上传下载删除文件

    在JAVA程序中,经常需要和FTP打交道,比如向FTP服务器上传文件.下载文件,本文简单介绍如何利用jakarta commons中的FTPClient(在commons-net包中)实现上传下载文件 ...

  9. SpringMVC ajax技术无刷新文件上传下载删除示例

    参考 Spring MVC中上传文件实例 SpringMVC结合ajaxfileupload.js实现ajax无刷新文件上传 Spring MVC 文件上传下载 (FileOperateUtil.ja ...

随机推荐

  1. Surrounded Regions leetcode java

    题目: Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is capt ...

  2. CentOS7.0 x86_64系统上构建php开发环境--Lamp(包含设置虚拟文件夹,加入SELinux对httpd的支持等知识)

    一.安装mysql,直接用yum安装就可以,mysql在centos7.0版本号中被mariadb替代了. 命令: yum install mysql-server mysql 安装好了,选择改动my ...

  3. POJ 2488 A Knight&#39;s Journey

    A Knight's Journey Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29226   Accepted: 10 ...

  4. eclipse全屏模式

  5. 【js】利用闭包消除回调函数启动时值已经发生变化的影响

    在以下代码中,timeFun异步执行了一个匿名函数,当输出color的值时已经由green变成red,因此输出为red. function timedFun(callback){ setTimeout ...

  6. uva 696 - How Many Knights

    题目链接:uva 696 - How Many Knights 题目大意:给出一个n * m的网格,计算最多可以放置几个国际象棋中的骑士. 解题思路:分成三类来讨论: 1)min(n, m) == 1 ...

  7. uni-app 如何开启sass\less处理

    开启方式:工具->插件安装->安装完成,启用即可

  8. 在VC中创建DLL文件的方法步骤

    一.Win32动态链接库 1.制作的步骤: (1)新建WIN32 Dynamic-link Library工程,工程名为MyDll,选择A simple DLL project类型. (2)MyDll ...

  9. mixin

    mixin.scss //-----------------------------------浏览器前缀----------------------------------------- //例子: ...

  10. JVM:垃圾回收机制和调优手段

    转载请注明出处: jiq•钦's technical Blog - 季义钦 引言: 我们都知道JVM内存由几个部分组成:堆.方法区.栈.程序计数器.本地方法栈 JVM垃圾回收仅针对公共内存区域即:堆和 ...