TELECHARGER DES FICHIERS, PAR LE PROTOCOLE HTTP

sparky_rv Messages postés 9 Date d'inscription samedi 17 janvier 2004 Statut Membre Dernière intervention 6 octobre 2004 - 6 oct. 2004 à 12:48
cerig Messages postés 2 Date d'inscription mardi 17 décembre 2002 Statut Membre Dernière intervention 21 septembre 2005 - 21 sept. 2005 à 15:58
Cette discussion concerne un article du site. Pour la consulter dans son contexte d'origine, cliquez sur le lien ci-dessous.

https://codes-sources.commentcamarche.net/source/23031-telecharger-des-fichiers-par-le-protocole-http

cerig Messages postés 2 Date d'inscription mardi 17 décembre 2002 Statut Membre Dernière intervention 21 septembre 2005
21 sept. 2005 à 15:58
sparky_rv Messages postés 9 Date d'inscription samedi 17 janvier 2004 Statut Membre Dernière intervention 6 octobre 2004
6 oct. 2004 à 12:48
salut !! sympa mais bloquant je l ai exuté dans un thread c est nikel parcontre je veux rajouter un barragrph ... comment recuperer la taille du fichier distant ?

pour le thread ca donne ca :
private void downloadURL(String url)
{
try
{
int lastIndex = url.LastIndexOf("/")+1;
string filename = url.Substring(lastIndex);
string pathnfile= Application.StartupPath+"\"+filename;
richTextBox1.AppendText("Downloading File :\n" + url + "\n");
myDownloadFile = new FileInfo(Application.StartupPath+"\"+filename);
myTimer.Enabled = true;
myURL = url;
myFile = pathnfile;
ThreadStart threadStart = new ThreadStart(downloadThread);
thread = new Thread(threadStart);
thread.Start();
richTextBox1.AppendText("\nfile saved in :\n\t" + Application.StartupPath +"\n");

}
catch(Exception e)
{
richTextBox1.AppendText("file NOT downloaded ... erreur during process\n"+e+"\n");
}

}
private void downloadThread()
{
WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(myURL,myFile);
myWebClient.Dispose();
}


(on remarquera la presence d un timer c est pour avoir l'evolution du fichier telechargé)

public void OnTimer(object sender, EventArgs e)
{
if(thread.IsAlive)
{
myDownloadFile.Refresh();
richTextBox1.AppendText(myDownloadFile.Length+"\n");
}
else myTimer.Enabled = false;


voila il me manque plus que la taille du fichier distant le rajouter dans mon baragraphe et c est la fet :p
Rejoignez-nous