// C#
public void DownloadDocument(string localFile,string remoteFile)
{
try
{
// Create the web request object
WebRequest request = WebRequest.Create(remoteFile);
request.Credentials = System.Net.CredentialCache.DefaultCredentials;
request.Method = "GET";
// Get a web response back
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream reader = response.GetResponseStream();
FileStream fstream = new FileStream(localFile, FileMode.OpenOrCreate, FileAccess.Write);
byte [] buffer = new byte[1024];
int bytesRead = 0;
do
{
bytesRead = reader.Read(buffer,0,1024);
fstream.Write(buffer,0,bytesRead);
} while(bytesRead >0);
response.Close();
fstream.Close();
}
catch(Exception ex)
{
MessageBox.Show(host.HostForm,ex.Message,"Error Downloading",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
Tuesday, April 19, 2005
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment