- Inscription
- 7 Juillet 2013
- Messages
- 1 883
- Réactions
- 365
- Points
- 5 148
WebClient client =newWebClient();
string desktop =Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
client.DownloadProgressChanged+=newDownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted+=newAsyncCompletedEventHandler(client_DownloadFileCompleted);
client.DownloadFileAsync(newUri("lien de téléchargement"), desktop +"nomdufichier.extension");
void client_DownloadProgressChanged(object sender,DownloadProgressChangedEventArgs e)
{
progressBarTelechargement.Maximum=(int)e.TotalBytesToReceive/100;
progressBarTelechargement.Value=(int)e.BytesReceived/100;
}
void client_DownloadFileCompleted(object sender,AsyncCompletedEventArgs e)
{
labelTelechargement.Text="Le téléchargement est terminé";
}
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
double bytesIn = double.Parse(e.BytesReceived.ToString());
double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
double percentage = bytesIn / totalBytes * 100;
Label1.Text = "Ton Text : " + Convert.ToInt32(percentage) + " %";
}
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
Aussi OuiSalut,
Le premier code est à mettre pour télécharger la mise à jour, les fonctions ci-dessous seront également exécutées.Code:WebClient client =newWebClient(); string desktop =Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory); client.DownloadProgressChanged+=newDownloadProgressChangedEventHandler(client_DownloadProgressChanged); client.DownloadFileCompleted+=newAsyncCompletedEventHandler(client_DownloadFileCompleted); client.DownloadFileAsync(newUri("lien de téléchargement"), desktop +"nomdufichier.extension");
Code:void client_DownloadProgressChanged(object sender,DownloadProgressChangedEventArgs e) { progressBarTelechargement.Maximum=(int)e.TotalBytesToReceive/100; progressBarTelechargement.Value=(int)e.BytesReceived/100; } void client_DownloadFileCompleted(object sender,AsyncCompletedEventArgs e) { labelTelechargement.Text="Le téléchargement est terminé"; }
Tu peux également faire un système qui indique le débit et avec un BackgroundWorker tu peux aussi mettre en pause ou arrêter le téléchargement comme ici :Vous devez être inscrit pour voir les liens ! Inscrivez-vous ou connectez-vous ici.
Sa na rien avoir ton french tool tu le sort se week ou aujourd'hui ?Aussi Oui
Je ne doit pas mettre le code dans un Timer pour que sa actualise a chaque fois ?Yo pour récupérer des info sur un Téléchargement ,
using System.Net;
//Cette Méthode ci-dessous ajoute les pourcentages de téléchargement en cours
//Dans ton démarrage de téléchargement tu ajoute ceciCode:void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e) { double bytesIn = double.Parse(e.BytesReceived.ToString()); double totalBytes = double.Parse(e.TotalBytesToReceive.ToString()); double percentage = bytesIn / totalBytes * 100; Label1.Text = "Ton Text : " + Convert.ToInt32(percentage) + " %"; }
Code:WebClient client = new WebClient(); client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
Ses pour un affichage en %
Nope regarde la fonction "Changed", ça actualise l'affichage de ta progressBar dès que la progression du téléchargement a changée. Par contre tu peux faire un BackGroundWorker et utiliser try catch pour le téléchargement (en cas d'erreur)Je ne doit pas mettre le code dans un Timer pour que sa actualise a chaque fois ?
Ah oui je regarderai un peut a ça donc si j'ai mit ça c'est bon ?Nope regarde la fonction "Changed", ça actualise l'affichage de ta progressBar dès que la progression du téléchargement a changée. Par contre tu peux faire un BackGroundWorker et utiliser try catch pour le téléchargement (en cas d'erreur)