我正在从网站上下载文件并且它总是保存到我的下载文件中,有没有办法可以选择将文件保存到哪里?
public void myDownloadfile(string token, string fileid, string platform)
{
Dictionary<string, string> parameters = new Dictionary<string, string>();
parameters.Add("Token", token);
parameters.Add("fileid", fileid);
parameters.Add("plateform", platform);
string url;
url = "https://formbase.formmobi.com/dvuapi/downloadfile.aspx?" + "token=" + token + "&fileid=" + fileid + "&platform=" + platform;
System.Diagnostics.Process.Start(url);
}
Run Code Online (Sandbox Code Playgroud)
System.Diagnostics.Process.Start
只需在所需的网址上打开默认的网络浏览器即可.
您可以将浏览器设置为打开另存为对话框.
但更好的使用WebClient.DownloadFile
:http://msdn.microsoft.com/en-us/library/ez801hhe.aspx
它接收目标文件的路径作为其中一个参数.
由于您使用系统的标准浏览器下载文件,因此必须更改其中的设置.
否则,您可能希望使用WebClient
该类来下载文件,因为它很容易使用
using System.Net;
WebClient webClient = new WebClient();
webClient.DownloadFile("http://mysite.com/myfile.txt", @"c:\myfile.txt");
Run Code Online (Sandbox Code Playgroud)
(例子来自这里)