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


C# System.Net.WebClient.DownloadFile方法代码示例

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


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

示例1: Action

        public override bool Action(string action)
        {
            bool result = base.Action(action);
            if (result && action == ACTION_IMPORT)
            {
                try
                {
                    using (var client = new Utils.API.GeocachingLiveV6(Core))
                    using (var wc = new System.Net.WebClient())
                    {
                        var resp = client.Client.GetGeocacheDataTypes(client.Token, true, true, true);
                        if (resp.Status.StatusCode == 0)
                        {
                            string defaultPath = Path.Combine(new string[] { _basePath, "Default", "attributes" });
                            if (!Directory.Exists(defaultPath))
                            {
                                Directory.CreateDirectory(defaultPath);
                            }
                            foreach (var attr in resp.AttributeTypes)
                            {
                                wc.DownloadFile(attr.YesIconName, Path.Combine(defaultPath, string.Format("{0}.gif", attr.ID)));
                                wc.DownloadFile(attr.NoIconName, Path.Combine(defaultPath, string.Format("_{0}.gif", attr.ID)));
                            }

                            defaultPath = Path.Combine(new string[] { _basePath, "Default", "cachetypes" });
                            if (!Directory.Exists(defaultPath))
                            {
                                Directory.CreateDirectory(defaultPath);
                            }

                            string smallPath = Path.Combine(new string[] { _basePath, "Small", "cachetypes" });
                            if (!Directory.Exists(smallPath))
                            {
                                Directory.CreateDirectory(smallPath);
                            }
                            foreach (var gt in resp.GeocacheTypes)
                            {
                                string fn = string.Format("{0}.gif", gt.GeocacheTypeId);
                                wc.DownloadFile(gt.ImageURL, Path.Combine(defaultPath, fn));
                            }

                            defaultPath = Path.Combine(new string[] { _basePath, "Default", "logtypes" });
                            if (!Directory.Exists(defaultPath))
                            {
                                Directory.CreateDirectory(defaultPath);
                            }
                            foreach (var gt in resp.WptLogTypes)
                            {
                                wc.DownloadFile(gt.ImageURL, Path.Combine(defaultPath, string.Format("{0}.gif", gt.WptLogTypeId)));
                            }
                        }
                    }
                }
                catch
                {
                }
            }
            return result;
        }
开发者ID:gahadzikwa,项目名称:GAPP,代码行数:59,代码来源:GetGroundspeakImages.cs

示例2: installGame

 private void installGame()
 {
     //download and unpack game   
     try
     {
         String filename = installerExe.Substring(0, installerExe.Length - 4);
         if (!System.IO.Directory.Exists(getDosBoxPath() + "\\" + filename))
         {
             System.Net.WebClient webc = new System.Net.WebClient();
             webc.DownloadFile(new Uri("https://gamestream.ml/games/" + installerExe), getDosBoxPath() + installerExe);
             Process process1 = Process.Start(getDosBoxPath() + installerExe);
             process1.WaitForExit();
             startDosBox();
         }
         else
         {
             startDosBox();
         }
     }
     catch (Exception e) {
         MessageBox.Show(e.Message);
         Application.ExitThread();
         Application.Exit();
     }
 }
开发者ID:ajaxweb,项目名称:Downloader,代码行数:25,代码来源:Downloader.cs

示例3: Webimage

 public static System.Drawing.Image Webimage(this string s)
 {
     var wc = new System.Net.WebClient { Proxy = null };
     var filesavepath = System.Windows.Forms.Application.StartupPath + "\\" + System.Guid.NewGuid();
     wc.DownloadFile(s, filesavepath);
     return System.Drawing.Image.FromFile(filesavepath);
 }
开发者ID:x-strong,项目名称:KCPlayer.Plugin.Share,代码行数:7,代码来源:BaseString.cs

示例4: GetAllEpisodes

        public List<Episode> GetAllEpisodes(int seriesId)
        {
            String zipPath = System.IO.Path.GetTempPath() + "en.zip";
            String unzipPath = System.IO.Path.GetTempPath() + "seriestracker unzip";
            String xmlPath = unzipPath + System.IO.Path.DirectorySeparatorChar + "en.xml";
            System.Net.WebClient client = new System.Net.WebClient();
            client.DownloadFile(GetZipUrl(seriesId), zipPath);
            using (ZipFile zip = ZipFile.Read(zipPath))
            {
                foreach (ZipEntry e in zip)
                {
                    e.Extract(unzipPath, ExtractExistingFileAction.OverwriteSilently);
                }
            }
            XDocument doc = XDocument.Load(xmlPath);
            var episodes = from episode in doc.Descendants("Episode")
                            where episode.Element("EpisodeName") != null && episode.Element("id") != null &&
                                  episode.Element("SeasonNumber") != null && episode.Element("EpisodeNumber") != null
                            select new Episode
                            {
                                Name = episode.Element("EpisodeName").Value,
                                Overview = episode.Element("Overview") != null ? episode.Element("Overview").Value : "",
                                Id = Convert.ToInt32(episode.Element("id").Value),
                                SeasonNumber = Convert.ToInt32(episode.Element("SeasonNumber").Value),
                                EpisodeNumber = Convert.ToInt32(episode.Element("EpisodeNumber").Value),
                                SeriesId = Convert.ToInt32(episode.Element("seriesid").Value),
                                FirstAired = Episode.DateToTimestamp(episode.Element("FirstAired").Value)
                            };

            return episodes.ToList();
        }
开发者ID:maigel,项目名称:SeriesTracker,代码行数:31,代码来源:ApiReader.cs

示例5: UpdateFileCached

 public static bool UpdateFileCached(string remoteUrl, string localUrl, int thresholdInHours = -1)
 {
     bool returnValue = false;
     DateTime threshold;
     if (thresholdInHours > -1)
     {
         threshold = DateTime.Now.AddHours(-thresholdInHours);
     }
     else
     {
         threshold = DateTime.MinValue;
     }
     try
     {
         if (!File.Exists(localUrl) || File.GetLastWriteTime(localUrl) < threshold)
         {
             Console.WriteLine("we need to re-download " + localUrl);
             using (System.Net.WebClient webClient = new System.Net.WebClient())
             {
                 webClient.DownloadFile(remoteUrl, localUrl);
                 returnValue = true;
             }
         }
         else
         {
             returnValue = true;
         }
     }
     catch(Exception e)
     {
         Debug.WriteLine(e);
         returnValue = false;
     }
     return returnValue;
 }
开发者ID:RParkerM,项目名称:PadMonsterInfo,代码行数:35,代码来源:Methods.cs

示例6: Run

 public int Run(Cli console,string[] args)
 {
     string source = null;
     string local  = null;
     Options opts = new Options("Downloads a specified file")
     {
         new Option((string s)=>source =s,"address","The source address of the file to be downloaded"),
         new Option((string l)=>local =l,"localFile","Save the remote file as this name"),
     };
     opts.Parse(args);
     if(source == null)
     {
         return 1;
     }
     using(var client = new System.Net.WebClient())
     {
         if(local !=null)
         {
             client.DownloadFile(new Uri(source),local);
         }
         else
         {
             var result = client.DownloadString(new Uri(source));
             console.Out.WriteLine(result);
         }
     }
     return 0;
 }
开发者ID:jmaxxz,项目名称:Jmaxxz.Console,代码行数:28,代码来源:Download.cs

示例7: CurrentWeather

        public CurrentWeather(string fetched, JObject json)
        {
            Fetched = fetched;
            Json = json;

            if (Json["current_observation"]["temp_f"] != null)
            {

                CurrentTempF = (double)Json["current_observation"]["temp_f"];
                FeelsLikeF = (double)Json["current_observation"]["feelslike_f"];
                CurrentTempC = (double)Json["current_observation"]["temp_c"];
                FeelsLikeC = (double)Json["current_observation"]["feelslike_c"];
                CityName = (string)Json["current_observation"]["display_location"]["full"];
                WindFeel = (string)Json["current_observation"]["wind_string"];
                WindSpeedMph = (double)Json["current_observation"]["wind_mph"];
                DewPointF = (double)Json["current_observation"]["dewpoint_f"];
                ForecastURL = (string)Json["current_observation"]["forecast_url"];
                VisibilityMi = (double)Json["current_observation"]["visibility_mi"];
                Weather = (string)Json["current_observation"]["weather"];
                Elevation = (string)Json["current_observation"]["observation_location"]["elevation"];

                ImageName = (string)Json["current_observation"]["icon"];
                ImageUrl = (string)Json["current_observation"]["icon_url"];

                string folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
                LocalUrl = System.IO.Path.Combine(folder, System.IO.Path.GetRandomFileName());
                System.Net.WebClient webClient = new System.Net.WebClient();
                webClient.DownloadFile(ImageUrl, LocalUrl);
            }
        }
开发者ID:KyleSwanson,项目名称:SLCCProjects,代码行数:30,代码来源:WeatherFetcher.cs

示例8: Page_Load

        protected void Page_Load(object sender, EventArgs e)
        {
            string siteid = Request["siteid"];
            string filename = Request["filename"];

            DataSet dsSite = DbHelper.GetSiteData(siteid, "");
            string tmpFolder = Server.MapPath("./") + "TempOutput" + "/" + Page.User.Identity.Name + "/";

            if (Directory.Exists(tmpFolder))
            {
                string[] files = Directory.GetFiles(tmpFolder);
                foreach (string file in files)
                    File.Delete(file);
            }
            else
            {
                Directory.CreateDirectory(tmpFolder);
            }

            foreach (DataRow drSite in dsSite.Tables[0].Rows)
            {
                string siteUrl = drSite["ZipApiUrl"].ToString() + "getfile.php?filename=" + filename;
                System.Net.WebClient client = new System.Net.WebClient();
                client.DownloadFile(siteUrl, tmpFolder + filename);

                Func.SaveLocalFile(tmpFolder + filename, "zip", "Mone\\CSV出力");
            }
        }
开发者ID:tuankyo,项目名称:QLTN,代码行数:28,代码来源:GetFile.aspx.cs

示例9: Form1_DragDrop

 public virtual void Form1_DragDrop(object sender, DragEventArgs e)
 {
     if (_isUrl)
     {
         string url = e.Data.GetData("Text") as string;
         if (string.IsNullOrEmpty(url) || !IsImage(url))
         {
             return;
         }
         using (System.Net.WebClient wc = new System.Net.WebClient())
         {
             _currentUri = url;
             _currentFile = "Browser";
             try
             {
                 wc.DownloadFile(url, _currentFile);
             }
             catch
             {
                 MessageBox.Show("画像のダウンロードに失敗しました", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     else
     {
         string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
         if (!File.Exists(files[0]) || !IsImage(files[0]))
         {
             return;
         }
         _currentFile = files[0];
         _currentUri = _currentFile;
     }
     FindImage(_currentFile);
 }
开发者ID:ksasao,项目名称:Gochiusearch,代码行数:35,代码来源:MainForm.cs

示例10: ImportMethod

        protected override void ImportMethod()
        {
            using (Utils.ProgressBlock progress = new Utils.ProgressBlock(this, STR_IMPORT, STR_DOWNLOAD, 1, 0))
            {
                using (System.IO.TemporaryFile tmp = new System.IO.TemporaryFile(true))
                using (System.Net.WebClient wc = new System.Net.WebClient())
                {
                    wc.DownloadFile("http://www.globalcaching.eu/service/cachedistance.aspx?country=Netherlands&prefix=GC", tmp.Path);

                    using (var fs = System.IO.File.OpenRead(tmp.Path))
                    using (ZipInputStream s = new ZipInputStream(fs))
                    {
                        ZipEntry theEntry = s.GetNextEntry();
                        byte[] data = new byte[1024];
                        if (theEntry != null)
                        {
                            StringBuilder sb = new StringBuilder();
                            while (true)
                            {
                                int size = s.Read(data, 0, data.Length);
                                if (size > 0)
                                {
                                    if (sb.Length == 0 && data[0] == 0xEF && size > 2)
                                    {
                                        sb.Append(System.Text.ASCIIEncoding.UTF8.GetString(data, 3, size - 3));
                                    }
                                    else
                                    {
                                        sb.Append(System.Text.ASCIIEncoding.UTF8.GetString(data, 0, size));
                                    }
                                }
                                else
                                {
                                    break;
                                }
                            }

                            XmlDocument doc = new XmlDocument();
                            doc.LoadXml(sb.ToString());
                            XmlElement root = doc.DocumentElement;
                            XmlNodeList nl = root.SelectNodes("wp");
                            if (nl != null)
                            {
                                Core.Geocaches.AddCustomAttribute(CUSTOM_ATTRIBUTE);
                                foreach (XmlNode n in nl)
                                {
                                    var gc = Utils.DataAccess.GetGeocache(Core.Geocaches, n.Attributes["code"].InnerText);
                                    if (gc != null)
                                    {
                                        string dist = Utils.Conversion.StringToDouble(n.Attributes["dist"].InnerText).ToString("000.0");
                                        gc.SetCustomAttribute(CUSTOM_ATTRIBUTE, dist);
                                    }
                                }
                            }
                        }
                    }

                }
            }
        }
开发者ID:RH-Code,项目名称:GAPP,代码行数:60,代码来源:GeocacheDistance.cs

示例11: Main

        static void Main(string[] args)
        {
            string s = @"http://192.168.3.12:8080/imc/nti/imcExport_exportPDF.action?a=1";
            System.Net.WebClient wc = new System.Net.WebClient();
            wc.DownloadFile(s, "aa.pdf");

            Console.ReadLine();
        }
开发者ID:dingxinbei,项目名称:LogWin,代码行数:8,代码来源:Program.cs

示例12: InstallNugetExe

 public static void InstallNugetExe(string nugetExePath)
 {
     if (!File.Exists(nugetExePath))
     {
         var directory = Path.GetDirectoryName(nugetExePath);
         Directory.CreateDirectory(directory);
         var client = new System.Net.WebClient();
         client.DownloadFile("http://nuget.org/nuget.exe", nugetExePath);
     }
 }
开发者ID:ryaneliseislalom,项目名称:corefxlab,代码行数:10,代码来源:PackageReader.cs

示例13: DownloadXML

		public void DownloadXML(System.String XmlURL)
		{
			System.String TempFile = PathSettings.TempPath + "TheLastRipperData.xml";
			if (System.IO.File.Exists(TempFile))
			{
				System.IO.File.Delete(TempFile);
			}
			System.Net.WebClient Client = new System.Net.WebClient();
			Client.DownloadFile(XmlURL, TempFile);
			this.FetchXML(TempFile);
		}
开发者ID:bossaia,项目名称:alexandrialibrary,代码行数:11,代码来源:Playlist.cs

示例14: Webimage

        /// <summary>
        /// WebPath -> Image
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
		public static System.Drawing.Image Webimage(this string s)
        {
            #region WebPath -> Image
            var wc = new System.Net.WebClient { Proxy = null };
            var filesavepath = System.Windows.Forms.Application.StartupPath + "\\" + System.Guid.NewGuid().ToString().Replace("-","");
            wc.DownloadFile(s, filesavepath);
            var img = System.Drawing.Image.FromFile(filesavepath);
            var bmp = new System.Drawing.Bitmap(img);
            filesavepath.ToDeleteFile();
            return bmp; 
            #endregion
        }
开发者ID:CraigTaylor,项目名称:App.Port,代码行数:17,代码来源:BaseImage.cs

示例15: Main

        static void Main(string[] args)
        {
            DBUtil.Connect();

            Logger.Instance.Debug("aa");

            // YPからチャンネル情報を取得
            List<ChannelDetail> channelDetails = GetChannelDetails();

            // 配信者マスターの更新
            UpdateChannel(channelDetails);

            // スレッド情報の更新
            UpdateBBSThread(channelDetails);

            // レス情報の更新
            UpdateBBSResponse();

            /*
            List<string> imgList = new List<string>();
            // レス一覧の取得
            List<BBSResponse> resList = BBSResponseDao.Select();
            foreach (BBSResponse res in resList)
            {
                Match match = Regex.Match(res.Message, @"ttp://.*\.(jpg|JPG|jpeg|JPEG|bmp|BMP|png|PNG)");

                if (match.Success)
                {
                    string imageUrl = "h" + match.Value;
                    imgList.Add(imageUrl);
                    ImageLinkDao.Insert(res.ThreadUrl, res.ResNo, imageUrl, res.WriteTime);
                }
            }
             */

            List<ImageLink> imageList = ImageLinkDao.Select();

            foreach (ImageLink link in imageList)
            {
                try
                {
                    System.Net.WebClient wc = new System.Net.WebClient();
                    wc.DownloadFile(link.ImageUrl, @"S:\MyDocument_201503\dev\github\PecaTsu_BBS\src_BBS\img\" + (link.WriteTime.Replace("/", "").Replace(":", "")) + ".jpg");
                    wc.Dispose();
                }
                catch (Exception)
                {
                }
            }

            DBUtil.Close();
        }
开发者ID:shule517,项目名称:PecaTsu,代码行数:52,代码来源:Program.cs


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