将文件保存到位置?

时间:2012-08-21 09:10:35

标签: c# file

我正在从网站上下载文件并且它总是保存到我的下载文件中,有没有办法可以选择将文件保存到哪里?

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);
}

5 个答案:

答案 0 :(得分:5)

System.Diagnostics.Process.Start只需在所需的网址上打开您的默认网络浏览器 您可以将浏览器设置为打开另存为对话框。

但最好使用WebClient.DownloadFilehttp://msdn.microsoft.com/en-us/library/ez801hhe.aspx 它接收目标文件的路径作为其中一个参数。

答案 1 :(得分:5)

由于您使用系统的标准浏览器下载文件,因此您必须更改其中的设置。


否则,您可能希望使用WebClient类来下载文件,因为它与

一样易于使用
using System.Net;

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

(来自here的例子)

答案 2 :(得分:1)

不要使用将启动默认浏览器的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")
    }

答案 3 :(得分:0)

您可以使用WebClient下载数据,并使用SaveFile对话框设置启动位置的默认位置。

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

答案 4 :(得分:0)

您可以使用HttpResponse

浏览链接:prompt a save dialog box to download a file

相关问题