sparky_rv
Messages postés9Date d'inscriptionsamedi 17 janvier 2004StatutMembreDerniè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");
}
21 sept. 2005 à 15:58
6 oct. 2004 à 12:48
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