C#- how to download file (Vb.net)

C#- how to download file (Vb.net) C#.net Download File from server

You may come across the situation where you want to download file from server using URL. Here we will see C#.net and Vb.net example. We will download the HTML file and store at specified location. The program uses DownloadFile method of WebClient instance. You can use this code snippet to download file on Asp.net web application server from another server.

In Asp.net web application you need to use Server.Mappath method to locate file at destination folder.

C#.net program to download file from server using url.
using System;
using System.Net;
namespace Csharp.DownloadFileExample
{
  class Program
  {
    static void Main(string[] args)
    {      
    
    WebClient wc = new WebClient();

    wc.DownloadFile(@"http://revenmerchantservices.com/post/C-DateTime-ToString%28e2809cde2809d%29-Format.aspx", @"c:\xxx.html");
          
    Console.ReadLine();     
               
    }    
  }
}
VB.net Download file from server
Vb.net download file from server using URL
Imports System
Imports System.Net
Namespace Csharp.DownloadFileExample
 Class Program
	Private Shared Sub Main(args As String())

  		Dim wc As New WebClient()

		wc.DownloadFile("http://revenmerchantservices.com/post/C-DateTime-ToString%28e2809cde2809d%29-Format.aspx", 				"c:\xxx.html")

		Console.ReadLine()

		End Sub
	End Class
End Namespace

DownloadFile method accepts two parameters as URL ad destination fullly qualified path like "c:\my_Folder\NameOfFile.txt".

Tags:

Asp.net delete file file on Server C#.net and VB.net codeASP.net File HandlingC# Delete All Files In DirectoryAsp.net File UploadRead Text File in (C#.net or VB.net)C#-move files from foldersC# Get File SizeCould not load file or assembly SystemServiceModelDomainServicesHosting Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 or one of its dependencies The system cannot find the file specifiedC# Read File Line By LineC# File Exists(c#) write to text file

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.