Sir, I want to know that how to download a file from URL using C#.NET.
I do a coding for the application about Download Manager,but at the time of downloading a file ie to save the file, the file is saved at its specified location ,but all files are corrupted.
So tell me that what type of coding i can do in C#.NET.

how to download a file ?
arkiboys
Sir the coding for the download manager i used is as follows
private void button1_Click(object sender, EventArgs e)
{
WebClient client = new WebClient();
string name1 = saveFileDialog1.FileName;
this.saveFileDialog1.InitialDirectory = System.Reflection.Assembly.GetExecutingAssembly().Location;
this.saveFileDialog1.Filter = "All Extensions (*.*)|*.*";
this.saveFileDialog1.FilterIndex = 1;
this.saveFileDialog1.RestoreDirectory = true;
Uri nuri = new Uri(textBox2.Text);
if (textBox1.Text.Length > 0 & textBox2.Text.Length > 0)
{
client.Proxy = WebRequest.DefaultWebProxy;
client.Credentials = CredentialCache.DefaultCredentials;
client.DownloadFileAsync(nuri,name1);
MessageBox.Show("Download Complete"+ saveFileDialog1.FileName);
}
}
In code textBox2.Text shows the URL address.Using this code file is saved but each files corrupts.
so please give me a correct solution.
Xadja
13117
I think you are opening file before it completely gets downloaded from the server, You are using asyncrhnous way to download file and you have to make sure that file has been totally been grabbed from the server before you open that. Try to add an event handler for DownloadFileCompleted event of WebClient and open that file only after that event is raised....
I hope this will help. Also try DownloadFile() instead of DownloadFileAsync() and see what happens..
Best Regards,
Rizwan
Rajesh Nagpal - MSFT
1. is this for a smart device, or is this for a PC which version of the Framework are you using (Compact Framework 1.0, Compact Framework 2.0)
2. show us the code you're already using that produces a corrupted file.
3. this may help: http://msdn2.microsoft.com/en-us/library/aa446517.aspx
datamark
Rizwan can you check this link for me