Pomster
Pomster

Reputation: 15197

Save file to location?

I am downloading a file off a website and it always saves into my Download files, is there a way where i can select where to save the file to?

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

Upvotes: 0

Views: 4141

Answers (5)

Vishal Suthar
Vishal Suthar

Reputation: 17194

You can use HttpResponse.

Go through the link: prompt a save dialog box to download a file

Upvotes: 0

Karl-Johan Sj&#246;gren
Karl-Johan Sj&#246;gren

Reputation: 17522

Don't use Process.Start that will launch the default browser to download the file and the download location will be very dependent on the users system settings. Use WebClient to download it instead and it will be easier to specify a 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.Net.WebClient wc = new System.Net.WebClient()
        wc.DownloadFile(url, "C:\\myFile.ext")
    }

Upvotes: 1

Schwarzie2478
Schwarzie2478

Reputation: 2276

You can use WebClient to download the data and use SaveFile Dialog to set the default location where you which to start.

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

Upvotes: 0

sloth
sloth

Reputation: 101052

Since you are downloading the file using your system's standard browser, you have to change the setting there.


Otherwise, you probably want to use the WebClient class to download a file, since it is as easy to use as

using System.Net;

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

(example from here)

Upvotes: 5

Svarog
Svarog

Reputation: 2208

System.Diagnostics.Process.Start just opens your default web browsers on the required url.
You can set your browser to open save as dialog.

But better use WebClient.DownloadFile: http://msdn.microsoft.com/en-us/library/ez801hhe.aspx It receives the path of the target file as one of it's parameters.

Upvotes: 5

Related Questions