Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to download a file to a specific path in from a given url in a windows form?

I need to download pdf files from a specified links(url) to a specific folder in a windows application using winforms please any one can suggest me with a solution.

like image 781
Arun Kumar Avatar asked Feb 01 '12 12:02

Arun Kumar


People also ask

How do I create a download folder in Windows 10?

Push the gray cogwheel button in the taskbar at the top and select "New Folder" from the dropdown menu. You will see a new folder appear named "untitled folder." Type "Downloads" to change the folder name so you know it is the folder that you are using to save downloads.

When I download a file where does it go?

You can find downloads on Android in My Files or File Manager. You can find these apps in the app drawer of your Android device. Within My Files or File Manager, navigate to the Downloads folder to find everything you downloaded.

How do I download a link?

Go to the webpage where you want to download a file. Touch and hold what you want to download, then tap Download link or Download image. To see all the files you've downloaded to your device, open the Downloads app.


3 Answers

using System.Net;

using (WebClient webClient = new WebClient())
{
    webClient.DownloadFile("http://mysite.com/myfile.txt", @"c:\myfile.txt");
}
like image 103
Viper Avatar answered Sep 19 '22 20:09

Viper


You can use the WebClient.DownloadFile method, available since .NET 2.0. It is usable from any type of application, not just Winforms.

You should be aware that DownloadFile blocks until the entire file finishes downloading. To avoid blocking you can use the WebClient.DownloadFileAsync method that will download in the background and raise the DownloadFileCompleted event when downloading finishes

like image 40
Panagiotis Kanavos Avatar answered Sep 20 '22 20:09

Panagiotis Kanavos


You could just "search the web" (aka google) for "C# download file", and end up with this simple MSDN example (modified to fit your specific question):

string remoteUri = "http://www.test.com/somefile.pdf";
string fileName = "c:\\targetfolder\\somefile.pdf";

WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(remoteUri,fileName);
like image 42
Christoffer Avatar answered Sep 20 '22 20:09

Christoffer