[英]C# WebClient.DownloadFile to specific path
Hi i'm trying to download a png file and place it in a custom location and i have tried adding to the line but wc.DownloadFile does not allow 3 arguments.嗨,我正在尝试下载一个 png 文件并将其放置在自定义位置,我曾尝试添加到该行,但 wc.DownloadFile 不允许 3 个参数。 does anyone have a suggestion?有人有建议吗? (rookie programmer) (菜鸟程序员)
if i change wc.DownloadFile to wc.DownloadFileAsync it gives me an error on y[2]如果我将 wc.DownloadFile 更改为 wc.DownloadFileAsync,它会在 y[2] 上给我一个错误
string lookat = args[0];
string[] exploded = lookat.Split('/');
WebClient wc = new WebClient();
wc.Proxy = new WebProxy();
string content = wc.DownloadString(args[0]);
Regex rx = new Regex("data-id=\"(.*)\">");
MatchCollection matches = rx.Matches(content);
string uri = "http://" + exploded[2] + "/v2/photo/=";
string id = matches[0].ToString().Replace("\"", "").Replace(">", "").Replace("data-id=", "");
content = wc.DownloadString(uri + id);
string[] res = content.Split(new string[] { "filetobedownloaded_" }, StringSplitOptions.None);
foreach (string s in res)
{
if (s.Contains(".png"))
{
string[] y = s.Replace("\\", "").Split('"');
wc.DownloadFile(y[2], "filetobedownloaded_" + y[0].Replace("_png", ".jpg"));
}
}
DownloadFileAsync
接受Uri
而不是string
因此您应该像这样将下载链接转换为Uri
:
wc.DownloadFileAsync(new Uri(y[2]), "C:\\" + "filetobedownloaded_" + y[0].Replace("_png", ".jpg"));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.