当前位置: 首页>>代码示例>>C#>>正文


C# WebClient.DownloadFileAsync方法代码示例

本文整理汇总了C#中System.Net.WebClient.DownloadFileAsync方法的典型用法代码示例。如果您正苦于以下问题:C# WebClient.DownloadFileAsync方法的具体用法?C# WebClient.DownloadFileAsync怎么用?C# WebClient.DownloadFileAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebClient的用法示例。


在下文中一共展示了WebClient.DownloadFileAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CCForm

 public CCForm()
 {
     InitializeComponent();
     string UpdatorApp = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), @"Updator\\UpdatorCC.exe"); //odkaz na spoustec minecraftu
     string remoteUri1 = "http://files.customcraft.cz/";
     string fileName1 = "verze.txt", myStringWebResource = null;
     string misto1 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), fileName1);
     WebClient verze1 = new WebClient();
     string App = "AppVerze.txt";
     string AppVerze = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), App);
     WebClient App1 = new WebClient();
     string spoustec1 = "AppVerze.txt";
     string spoustecweb1 = "Install\\AppVerze.txt";
     string spoustec = System.IO.File.ReadAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), spoustec1)); //verze updatu na webu
     string spoustecweb = System.IO.File.ReadAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), spoustecweb1)); //verze klienta
     if (spoustec == spoustecweb)
         {
             //vysere se na vše a pokračuje na CCFORM_Load
         }
     else
         {
             System.Diagnostics.Process.Start(UpdatorApp); //smaže složku Install a reinstaluje klienta
             Application.Exit();
         }
     myStringWebResource = remoteUri1 + fileName1;
     verze1.DownloadFileAsync(new Uri(myStringWebResource), misto1);
     //stažení verze klienta z webu
     myStringWebResource = remoteUri1 + fileName1;
     verze1.DownloadFileAsync(new Uri(myStringWebResource), AppVerze);
     //Stažení verze spouštěče k aktualizaci
 }
开发者ID:vavraCZe,项目名称:CustomCraftLauncher,代码行数:31,代码来源:Form1.cs

示例2: KeppySynthUpdateDL_Load

        private void KeppySynthUpdateDL_Load(object sender, EventArgs e)
        {
            using (webClient = new WebClient())
            {
                webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
                webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);

                if (test == 0)
                {
                    URL = new Uri(String.Format("https://github.com/KaleidonKep99/Keppy-s-Synthesizer/releases/download/{0}/KeppysSynthSetup.exe", VersionToDownload));
                }
                else
                {
                    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
                    URL = new Uri(FullURL);
                }

                try
                {
                    if (test == 0)
                    {
                        webClient.DownloadFileAsync(URL, String.Format("{0}KeppySynthSetup.exe", Path.GetTempPath()));
                    }
                    else
                    {
                        string userfolder = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\Keppy's Synthesizer";
                        webClient.DownloadFileAsync(URL, String.Format("{0}\\{1}", userfolder, FullURL.Split('/').Last()));
                    }
                }
                catch
                {
                    MessageBox.Show("The configurator can not connect to the GitHub servers.\n\nCheck your network connection, or contact your system administrator or network service provider.", "Keppy's Synthesizer - Connection error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
开发者ID:KaleidonKep99,项目名称:Keppy-s-Driver,代码行数:35,代码来源:KeppySynthDLEngine.cs

示例3: DownloadLWJGL

        public DownloadLWJGL(MainForm form, String path)
        {
            this.form = form;
            this.path = path;

            if (File.Exists(path + "natives.zip"))
                File.Delete(path + "natives.zip");
            if (File.Exists(path + "lwjgl.jar"))
                File.Delete(path + "lwjgl.jar");
            if (File.Exists(path + "jinput.jar"))
                File.Delete(path + "jinput.jar");
            if (File.Exists(path + "lwjgl_util.jar"))
                File.Delete(path + "lwjgl_util.jar");

            if (!Directory.Exists(path))
                Directory.CreateDirectory(path);
            native = new Uri(downloadLink + "windows_natives.jar");
            lwjgl = new Uri(downloadLink + "lwjgl.jar");
            jinput = new Uri(downloadLink + "jinput.jar");
            util = new Uri(downloadLink + "lwjgl_util.jar");

            WebClient client = new WebClient();
            client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(form.SetProgressBar); //TODO: Don't use mainForm
            client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(Downloaded);

            form.SetTask("Downloading Natives");                                                            //TODO: ^
            client.DownloadFileAsync(native, path + "natives.zip");

            while (isDownloading) {
                Application.DoEvents();
            }
            isDownloading = true;
            form.SetTask("Downloading LWJGL");                                                              //TODO: ^
            client.DownloadFileAsync(lwjgl, path + "lwjgl.jar");

            while (isDownloading) {
                Application.DoEvents();
            }
            isDownloading = true;
            form.SetTask("Downloading JInput");                                                             //TODO: ^
            client.DownloadFileAsync(jinput, path + "jinput.jar");

            while (isDownloading) {
                Application.DoEvents();
            }
            isDownloading = true;
            form.SetTask("Downloading LWJGL Util");                                                         //TODO: ^
            client.DownloadFileAsync(util, path + "jwjgl_util.jar");

            while (isDownloading) {
                Application.DoEvents();
            }
        }
开发者ID:SinZ163,项目名称:SinZationalMinecraftLauncher,代码行数:53,代码来源:DownloadLWJGL.cs

示例4: btnDownload_Click

        private void btnDownload_Click(object sender, EventArgs e)
        {
            EnableControl(false);
            if (CheckVariable())
            {
                var downloadsrc = new DownloadSource(textLink.Text);
                if (downloadsrc.LinkXml != null)
                {
                    var dir = textDSTdownload.Text;
                    var webClient = new WebClient();
                    int i = 0;
                    webClient.DownloadFileAsync(new Uri(downloadsrc.ListMusics.DsItems[i].Music.Source),
                        dir + @"\" + downloadsrc.ListMusics.DsItems[i].Music.Title + "." +
                        downloadsrc.ListMusics.DsItems[i].Type);
                    webClient.DownloadProgressChanged += (u, v) =>
                    {
                        toolStripLbtitle.Text = string.Format("{0} - {1} %",
                            downloadsrc.ListMusics.DsItems[i].Music.Title, v.ProgressPercentage);
                    };
                    webClient.DownloadFileCompleted += (u, v) =>
                    {
                        if (i < downloadsrc.ListMusics.DsItems.Count - 1)
                        {
                            i++;
                            webClient.DownloadFileAsync(new Uri(downloadsrc.ListMusics.DsItems[i].Music.Source),
                                dir + @"\" + downloadsrc.ListMusics.DsItems[i].Music.Title + "." +
                                downloadsrc.ListMusics.DsItems[i].Type);
                        }
                        else
                        {
                            MessageBox.Show(@"Download Complete!");
                            EnableControl(true);
                        }

                    };
                }
                else
                {
                    MessageBox.Show("Link download nhạc không hợp lệ!");
                    EnableControl(true);
                }
            }
            else
            {
                MessageBox.Show("Lỗi chưa chọn đường dẫn!");
                EnableControl(true);
            }

        }
开发者ID:ThinhTu,项目名称:Download_music_mp3.zing.vn,代码行数:49,代码来源:MainForm.cs

示例5: CheckForUpdates

        static void CheckForUpdates()
        {
            UpdaterMode updaterMode = ConfigKey.UpdaterMode.GetEnum<UpdaterMode>();
            if( updaterMode == UpdaterMode.Disabled ) return;

            UpdaterResult update = Updater.CheckForUpdates();

            if( update.UpdateAvailable ) {
                Console.WriteLine( "** A new version of LegendCraft is available: {0}, released {1:0} day(s) ago. **",
                                   update.LatestRelease.VersionString,
                                   update.LatestRelease.Age.TotalDays );
                if( updaterMode != UpdaterMode.Notify ) {
                    WebClient client = new WebClient();
                    client.DownloadProgressChanged += OnUpdateDownloadProgress;
                    client.DownloadFileCompleted += OnUpdateDownloadCompleted;
                    client.DownloadFileAsync( update.DownloadUri, Paths.UpdaterFileName );
                    UpdateDownloadWaiter.WaitOne();
                    if( updateFailed ) return;

                    if( updaterMode == UpdaterMode.Prompt ) {
                        Console.WriteLine( "Restart the server and update now? y/n" );
                        var key = Console.ReadKey();
                        if( key.KeyChar == 'y' ) {
                            RestartForUpdate();
                            return;
                        } else {
                            Console.WriteLine( "You can update manually by shutting down the server and running " + Paths.UpdaterFileName );
                        }
                    } else {
                        RestartForUpdate();
                        return;
                    }
                }
            }
        }
开发者ID:Eeyle,项目名称:LegendCraftSource,代码行数:35,代码来源:Program.cs

示例6: SharpUpdateDownloadForm

        internal SharpUpdateDownloadForm(Uri location, string md5, Icon programIcon)
        {
            InitializeComponent();
            if (programIcon != null)
                this.Icon = programIcon;

            tempFile = Path.GetTempFileName();
            this.md5 = md5;

            webClient = new WebClient();
            webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
            webClient.DownloadFileCompleted += WebClient_DownloadFileCompleted;

            bgWorker = new BackgroundWorker();
            bgWorker.DoWork += BgWorker_DoWork;
            bgWorker.RunWorkerCompleted += BgWorker_RunWorkerCompleted;
            try
            {
                webClient.DownloadFileAsync(location, tempFile);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                this.DialogResult = DialogResult.No;
                this.Close();
            }
        }
开发者ID:barwis,项目名称:WoT_modDownloader,代码行数:27,代码来源:SharpUpdateDownloadForm.cs

示例7: BeginDownloadFile

 public void BeginDownloadFile(string weburl, string destfile, bool showprogress)
 {
     ThreadPool.QueueUserWorkItem(delegate (object o) {
         WebClient client = new WebClient();
         if (weburl != "")
         {
             EventLog.WriteLine("Download File", new object[0]);
             EventLog.WriteLine(destfile, new object[0]);
             EventLog.WriteLine(weburl, new object[0]);
             try
             {
                 if (showprogress)
                 {
                     Program.MainForm.Invoke((VGen1)delegate (object objclient) {
                         try
                         {
                             new DlgDownloadProgress(Loc.Get("<LOC>Downloading"), objclient as WebClient).Show();
                         }
                         catch (Exception exception)
                         {
                             ErrorLog.WriteLine(exception);
                         }
                     }, new object[] { client });
                 }
                 client.DownloadFileCompleted += new AsyncCompletedEventHandler(this.client_DownloadFileCompleted);
                 client.DownloadFileAsync(new Uri(weburl), destfile);
             }
             catch (Exception exception)
             {
                 ErrorLog.WriteLine(exception);
             }
         }
     });
 }
开发者ID:micheljung,项目名称:gpgnetfix,代码行数:34,代码来源:WebDownloader.cs

示例8: UpdateFiles

 private void UpdateFiles()
 {
     WebClient wc = new WebClient();
     wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
     wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted);
     wc.DownloadFileAsync(new Uri(updateServer + "latest.zip"), Path.GetDirectoryName(Application.ExecutablePath) + "\\latest.zip");
 }
开发者ID:pederjohnsen,项目名称:Nimbus,代码行数:7,代码来源:Form1.cs

示例9: StartUpdate

 public void StartUpdate()
 {
     WebClient wc = new WebClient();
     wc.DownloadProgressChanged += wc_DownloadProgressChanged;
     wc.DownloadFileCompleted += wc_DownloadFileCompleted;
     wc.DownloadFileAsync(new Uri(Link), "update.zip");
 }
开发者ID:banksyhf,项目名称:Auxilium-2,代码行数:7,代码来源:Updater.cs

示例10: Download

 /// <summary>
 /// Download the MPQ Files which are in nodeList and not in mpqFiles
 /// </summary>
 /// <param name="nodeList">Node List existing in version.xml</param>
 /// <param name="mpqFiles">MPQ Files existing in Data/ directory</param>
 /// <param name="dataDir">Absolute path to Data/ directory</param>
 public void Download(XmlNodeList nodeList, FileInfo[] mpqFiles, string dataDir)
 {
     DialogResult result = MessageBox.Show("Une nouvelle mise à jour a été trouvée !\r\n Télécharger ?", "Avertissement", MessageBoxButtons.OKCancel);
     if (result == DialogResult.Cancel)
     {
         Close();
     }
     else
     {
         foreach (XmlNode node in nodeList)
         {
             if (!mpqFiles.Contains(new FileInfo(node.InnerText)))
             {
                 // Have to create two WebClient
                 WebClient webClient = new WebClient();
                 WebClient webClient2 = new WebClient();
                 labelDl.Text = "Téléchargement de la mise à jour : " + node.Attributes["nom"].Value;
                 webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);
                 webClient2.DownloadStringCompleted += new DownloadStringCompletedEventHandler(webClient2_DownloadStringCompleted);
                 webClient2.DownloadStringAsync(new Uri(node.Attributes["desc"].Value));
                 webClient.DownloadFileAsync(new Uri(node.Attributes["lien"].Value), Path.Combine(dataDir, node.InnerText));
             }
         }
         buttonClose.Visible = true;
     }
 }
开发者ID:pauljenny,项目名称:Launcher,代码行数:32,代码来源:DownloaderBox.cs

示例11: findSoundName

		public void findSoundName() {
			if (!File.Exists(vsnd_to_soundname_Path)) {
				DialogResult dr = MetroMessageBox.Show(mainForm,
					strings.CouldntFindRequiredFile + ": " + vsnd_to_soundname_Path + ". " + strings.D2ModKitWillDownloadItNow,
					strings.CouldntFindRequiredFile,
					MessageBoxButtons.OKCancel,
					MessageBoxIcon.Error);

				if (dr != DialogResult.OK) {
					return;
				}

				using (WebClient SoundMapFileWC = new WebClient()) {
					SoundMapFileWC.DownloadFileCompleted += SoundMapFileWC_DownloadFileCompleted;
					mainForm.progressSpinner1.Visible = true;
					mainForm.findSoundNameBtn.Enabled = false;
					try {
						SoundMapFileWC.DownloadFileAsync(new Uri("https://github.com/stephenfournier/Dota-2-ModKit/raw/326ebd10a117c5f58c20b412a6e2f5e221800330/Dota2ModKit/Libs/vsnd_to_soundname_v2.txt"), "vsnd_to_soundname_v2.txt");
					} catch (Exception) {
						mainForm.progressSpinner1.Visible = false;
						mainForm.findSoundNameBtn.Enabled = true;
					}
                }
				return;
			}

			// we have a vsnd_to_soundname.txt at this point.
			if (vsndToName.Count == 0) {
				populateVsndToName();
			}

			FindSoundForm fsf = new FindSoundForm(mainForm);
			DialogResult dr2 = fsf.ShowDialog();

		}
开发者ID:KimimaroTsukimiya,项目名称:Dota-2-ModKit,代码行数:35,代码来源:SoundFeatures.cs

示例12: downloadPatch

        public void downloadPatch(Patch patch)
        {
            string downloadURL = URLFormatter.format($"{serverToDownload.website}/{serverToDownload.downloadDirectory}/");
            using (WebClient webClient = new WebClient())
            {
                string patchDownloadURL = downloadURL + "/" + patch.fileName;
                if (!ResourceHelper.resourceExists(patchDownloadURL))
                {
                    form.downloadStatusLabel.Text = $"Status: Could not download {patch.fileName} - It does not exist";
                    return;
                }

                ApplicationStatus.downloading = true;

                string localPatchDirectory = $"{serverToDownload.clientDirectory}/Data/";
                string localPatchPath = localPatchDirectory + patch.fileName;

                if (!Directory.Exists(localPatchDirectory))
                    Directory.CreateDirectory(localPatchDirectory);

                webClient.DownloadProgressChanged += downloadPatchProgressChanged;
                webClient.DownloadFileAsync(new System.Uri(patchDownloadURL), localPatchPath);
                webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(this.downloadPatchCompleted);
                stopWatch.Start();

                patchesToDownload.Remove(patch);
            }
        }
开发者ID:Freddan962,项目名称:WoWLauncher,代码行数:28,代码来源:PatchDownloader.cs

示例13: DownloadFile

        public static void DownloadFile()
        {
            if(Globals.OldFiles.Count <= 0)
            {
                Common.ChangeStatus(Texts.Keys.CHECKCOMPLETE);
                Common.EnableStart();
                return;
            }

            if (curFile >= Globals.OldFiles.Count)
            {
                Common.ChangeStatus(Texts.Keys.DOWNLOADCOMPLETE);
                Common.EnableStart();
                return;
            }

            if (Globals.OldFiles[curFile].Contains("/"))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(Globals.OldFiles[curFile]));
            }

            WebClient webClient = new WebClient();

            webClient.DownloadProgressChanged   += new DownloadProgressChangedEventHandler(webClient_DownloadProgressChanged);

            webClient.DownloadFileCompleted     += new AsyncCompletedEventHandler(webClient_DownloadFileCompleted);

            stopWatch.Start();

            webClient.DownloadFileAsync(new Uri(Globals.ServerURL + Globals.OldFiles[curFile]), Globals.OldFiles[curFile]);
        }
开发者ID:retvari,项目名称:game-patcher,代码行数:31,代码来源:FileDownloader.cs

示例14: DownloadTDBAsync

        public static Task DownloadTDBAsync(IProgress<int> progress, string downloadTo, string version = "")
        {

            return Task.Run(() =>
            {

                Uri uri;

                if (string.IsNullOrEmpty(version))
                    uri = new Uri(TDBLatestDownloadUrl);
                else
                    uri = new Uri(TDBPreviousDownloadUrl + version);

                ManualResetEvent mre = new ManualResetEvent(false);

                using (WebClient client = new WebClient())
                {
                    client.DownloadFileCompleted += (sender, e) => mre.Set();
                    client.DownloadProgressChanged += (sender, e) => progress.Report(e.ProgressPercentage);
                    client.DownloadFileAsync(uri, downloadTo);
                }

                mre.WaitOne();

            });

        }
开发者ID:TrinityCore-Manager,项目名称:TrinityCore-Manager-v3,代码行数:27,代码来源:TDB.cs

示例15: Download

 public void Download(WebSong webSong, string downloadPath)
 {
     using (var webClient = new WebClient())
     {
         webClient.DownloadFileAsync(new Uri(webSong.AudioUrl), Path.Combine(downloadPath, webSong.Artist + " - " + webSong.Name));
     }
 }
开发者ID:JLignell,项目名称:Jokify,代码行数:7,代码来源:SongFinderService.cs


注:本文中的System.Net.WebClient.DownloadFileAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。