本文整理汇总了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;
}
示例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();
}
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
}
示例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出力");
}
}
示例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);
}
示例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);
}
}
}
}
}
}
}
}
示例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();
}
示例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);
}
}
示例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);
}
示例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
}
示例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();
}