Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting files through http
Message
 
À
31/05/2006 21:59:23
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01126360
Message ID:
01126648
Vues:
19
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform