//--------------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);
}
}