簡體   English   中英

將文件保存到位置?

[英]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.DownloadFilehttp : //msdn.microsoft.com/zh-cn/library/ez801hhe.aspx它接收目標文件的路徑作為其參數之一。

由於要使用系統的標准瀏覽器下載文件,因此必須在此更改設置。


否則,您可能想使用WebClient類下載文件,因為它易於使用,

using System.Net;

WebClient webClient = new WebClient();
webClient.DownloadFile("http://mysite.com/myfile.txt", @"c:\myfile.txt");

這里的示例)

不要使用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下載數據,並使用“保存文件”對話框設置要從其開始的默認位置。

http://www.techrepublic.com/blog/programming-and-development/download-files-over-the-web-with-nets-webclient-class/695

您可以使用HttpResponse

瀏覽鏈接: 提示保存對話框以下載文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM