Get a file from Web Server using WebDAV in .net

B

bigrich

Hi all,
I'm getting in trouble with the Auto Update feature in my project, we need
to use HttpWebRequest/HttpWebResponse to get a file from the web server and
copy it to the local. Below is the sample code I'm using, actually it works
quite good on my other 2 Windows 2000 servers, but when I migrated the
server to our production server which is another 2K advanced server, it
always encounter the 501 error: Not implemented. Any input will be very
appreciated.

--------
private void button1_Click(object sender, System.EventArgs e)
{
string url="http://myServer/AdvancedSample_WebService/AppBuilds/";
bool deep = false;
//Retrieve the File
HttpWebRequest Request = (HttpWebRequest)HttpWebRequest.Create(url);
Request.Headers.Add("Translate: f");
Request.Credentials = CredentialCache.DefaultCredentials;

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>";

Request.Method = "PROPFIND";
if (deep == true)
Request.Headers.Add("Depth: infinity");
else
Request.Headers.Add("Depth: 1");
Request.ContentLength = requestString.Length;
Request.ContentType = "text/xml";
MessageBox.Show("Start get response.....");

Stream requestStream = Request.GetRequestStream();
MessageBox.Show("End get response.....");

requestStream.Write(Encoding.ASCII.GetBytes(requestString),0,Encoding.ASCII.
GetBytes(requestString).Length);
requestStream.Close();

HttpWebResponse Response;
StreamReader respStream;
try
{
Response = (HttpWebResponse)Request.GetResponse();
respStream = new StreamReader(Response.GetResponseStream());
}
catch (Exception ex)
{
Debug.WriteLine("APPMANAGER: Error accessing Url " + url);
throw ex;
}
}
------------
 
A

Alok

Why don't you try the WebClient object ??
It is much simpler and elegant.
it directly exposes a DownloadFile() method
HTH :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top