This following code describes about a common requirement of transferring files from one web server to another web server.
//
// For downloading the file
//
try
{ WebClient oclient = new WebClient();
oclient.DownloadFile(txtURL.Text,txtFileLocation.Text);
lblStatus.Text = "Check the file at " + txtFileLocation.Text;
}
catch (Exception ex)
{ lblStatus.Text = ex.Message;
}
//
// For uploading the file
//
try
{ WebClient oclient = new WebClient();
byte[] responseArray =
oclient.UploadFile(txtURLToSend.Text,"POST",txtFileToSend.Text);
lblStatus.Text =
"Check the file at " + Encoding.ASCII.GetString(responseArray);
}
catch (Exception ex)
{ lblStatus.Text = ex.Message;
}