Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting files through http
Message
 
To
31/05/2006 21:59:23
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01126360
Message ID:
01126648
Views:
25
Hi, Dude!

It seems that the Encoding is messing with the binary data you are downloading. When the data is encoded from a byte array to a string, some sequences of bytes are changed, making your file to become currupted.

I think that the following code will make it:
private void DownloadFile(string url)
{
    string fileLocationWhenDownloaded = Path.Combine("C:\\", Path.GetFileName(url));

    byte [] downloadedBytes;
        
    WebClient webClient = new WebClient();
    downloadedBytes = webClient.DownloadData(url);

    
    FileStream fs = new FileStream(fileLocationWhenDownloaded, FileMode.CreateNew);
    fs.Write(downloadedBytes, 0, downloadedBytes.Length);
    fs.Flush();
    fs.Close();
}
call it passing the url of the file to be downloaded:
DownloadFile("http://YourSite/YourFile.Zip");
HTH.
-----
Fabio Vazquez
http://www.fabiovazquez.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform