Hi, i would like to list files on remote sever (HTTP) Please advice me on possible options for a console application.
A:
If your http serer use webdav it is simple to do. Here some example code: Beware that you have to include a reference in your project to MSXML2 Com object
public static void PrintDirectoryContents(string url, bool deep) {
var xmlHttp_ = new XMLHTTP();
// Build the query.
string requestString =
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
"<a:propfind xmlns:a=\"DAV:\">" +
"<a:prop>" +
"<a:displayname/>" +
"<a:iscollection/>" +
"<a:getlastmodified/>" +
"</a:prop>" +
"</a:propfind>";
// Open a connection to the server.
xmlHttp_.open("PROPFIND", url, false, "youruser", "yourpassword");
// Send the request.
xmlHttp_.setRequestHeader("PROPFIND", requestString);
xmlHttp_.send(null);
// Get the response.
string folderList = xmlHttp_.responseText;
// Parse the folder list.
XmlDocument XmlDoc = new XmlDocument();
var xml = folderList;
XmlDoc.LoadXml(xml);
//HERE you can read the xmldocument for the
//properties of the files you need
}
Andrea Parodi
2010-09-07 19:43:27
Ok. thanks. I would also be grateful for an alternate example too. Thanks in advance.
2010-09-07 19:48:08
A:
You can use the WebClient class to call your server, read the file/directory lists and navigate through the directories recursively.
Here is the basic use of WebClient:
WebClient client = new WebClient ();
Stream data = client.OpenRead ("http://example.com");
StreamReader reader = new StreamReader(data);
string s = reader.ReadToEnd ();
// At this point, the variable s contains the returned webpage
Another option, which may be more suitable, it to use the HTML Agility Pack - you can use the WebHtml object to retrieve HTML directly from the web and then query it using XPath syntax.
Oded
2010-09-07 19:49:10