[英]Save file to location?
我正在從網站上下載文件,並且該文件始終保存到我的下載文件中,有沒有一種方法可以選擇將文件保存到何處?
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);
}
System.Diagnostics.Process.Start
只是在所需的URL上打開默認的Web瀏覽器。
您可以將瀏覽器設置為打開另存為對話框。
但是最好使用WebClient.DownloadFile
: http : //msdn.microsoft.com/zh-cn/library/ez801hhe.aspx它接收目標文件的路徑作為其參數之一。
不要使用Process.Start啟動默認的瀏覽器來下載文件,下載位置將非常取決於用戶的系統設置。 改用WebClient下載它,這樣可以更輕松地指定位置。
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.Net.WebClient wc = new System.Net.WebClient()
wc.DownloadFile(url, "C:\\myFile.ext")
}
您可以使用WebClient下載數據,並使用“保存文件”對話框設置要從其開始的默認位置。
您可以使用HttpResponse
。
瀏覽鏈接: 提示保存對話框以下載文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.