maevacmoi
Messages postés44Date d'inscriptionmercredi 1 octobre 2003StatutMembreDernière intervention 1 décembre 2003
-
27 oct. 2003 à 16:43
crack_xp
Messages postés91Date d'inscriptionsamedi 28 février 2004StatutMembreDernière intervention25 janvier 2007
-
24 mai 2004 à 18:07
Hello !
J'ai un fichier (exe) sauvegardé sur un serveur, et voudrai l'enregistrer en local, à l'aide d'une fonction recevant en paramètre string source et string destination. Malheureusement elle ne semble que fonctionner avec des fichiers textes style xml, xsd ... Pouvez-vous me dire ou se situe l'erreur. Fonction ci-dessous :
public string dataUpload(string source, string destination)
{
string donnees = "";
try
{
WebClient client = new WebClient();
// ouverture du fichier dans un stream
Stream data = client.OpenRead(source);
StreamReader reader = new StreamReader(data);
string str = "";
str = reader.ReadLine();
while(str != null)
{
// stockage des données dans la variable ligne par ligne
donnees += str;
str = reader.ReadLine();
}
data.Close();
saveFichier(donnees, destination);
return "ok";
}
catch(WebException exp)
{
// Si erreur, retour de l'exception
return exp.ToString();
}
}
crack_xp
Messages postés91Date d'inscriptionsamedi 28 février 2004StatutMembreDernière intervention25 janvier 2007 24 mai 2004 à 18:07
voila un code qui marche tres bien,!!
string remoteUri = "http://www.contoso.com/library/homepage/images/";string fileName "ms-banner.gif", myStringWebResource null;
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Concatenate the domain with the Web resource filename.
myStringWebResource = remoteUri + fileName;
Console.WriteLine("Downloading File "{0}" from "{1}" .......\n\n", fileName, myStringWebResource);
// Download the Web resource and save it into the current filesystem folder.
myWebClient.DownloadFile(myStringWebResource,fileName);
Console.WriteLine("Successfully Downloaded File "{0}" from "{1}"", fileName, myStringWebResource);
Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);