.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> Network >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Download a file from specified URL and save it on local machine.

Posted By:shiv chandra       Posted Date: June 30, 2011    Points: 40    Category: Network    URL: http://www.dotnetspark.com  

Download a file from specified URL and save it on local machine.
 

function for download file.
/// 
/// Download a file from specified URL and save it on local machine.
/// 
/// URL from where you want to download file.
public void DownloadFile(string URL, string LocalPath)
{
    try
    {
        System.Net.WebClient WebClient = new System.Net.WebClient();
        
        // Downloads the resource with the specified URI to a local file.
        WebClient.DownloadFile(URL, LocalPath);
    }
    catch (Exception e)
    {
        Console.WriteLine("Error: {0}", e.ToString());
    }
}
Call above function
//Calling function:
DownloadFile("http://www.Website.com/demo.rar", @"C:\download\file.zip");


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend