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".

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5