Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download file from web and then save with a save file dialog box?

Tags:

c#

download

save

How can I download a file, then save it to wherever I want? I am using Windows Form, Web Application.

I know I can download it with this code:

WebClient wClient = new WebClient();
wClient.DownloadFile("WebLinkHere", @"C:\File.txt");

But I want a save box like when you press CTRL+S.

like image 988
user2944342 Avatar asked Oct 19 '25 10:10

user2944342


1 Answers

You can use SaveFileDialog class. Example:

var dialog = new SaveFileDialog();
dialog.Filter = "Archive (*.rar)|*.rar";

var result = dialog.ShowDialog(); //shows save file dialog
if(result == DialogResult.OK)
{
    Console.WriteLine ("writing to: " + dialog.FileName); //prints the file to save

    var wClient = new WebClient();
    wClient.DownloadFile("WebLinkHere", dialog.FileName);
}

will show next dialog and if you search for next folder enter image description here

application will print:

writing to: C:\Temp\archiveName.rar
like image 137
Ilya Ivanov Avatar answered Oct 21 '25 23:10

Ilya Ivanov