In this article I will explain with an example, how to download Text file (.txt) from URL in ASP.Net using C# and VB.Net.
First, the Text file will be downloaded from the URL using WebClient class and then will be saved in a Server's Folder (Directory) using C# and VB.Net.
 
 

TXT File URL

The following TXT file will be used in this article.
Download Text File (.txt) from URL in ASP.Net using C# and VB.Net
 
 

Namespaces

You will need to import the following namespace.
C#
using System.Net;
 
VB.Net
Imports System.Net
 
 

Downloading TXT File from URL in ASP .Net

Inside the Page_Load event handler, the TXT file is downloaded from the URL using DownloadFile method of the WebClient class.

DownloadFile method

It accepts the following two parameters:
address – The URL of the file to be downloaded.
fileName – Path of the Folder (Directory) where the file will be downloaded.
C#
protected void Page_Load(object sender, EventArgs e)
{
    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
    WebClient webClient = new WebClient();
    webClient.DownloadFile("https://raw.githubusercontent.com/aspsnippets/test/master/ReadMe.txt", @"D:\Files\ReadMe.txt");
}
 
VB.Net
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    ServicePointManager.Expect100Continue = True
    ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
    Dim webClient As WebClient = New WebClient()
    webClient.DownloadFile("https://raw.githubusercontent.com/aspsnippets/test/master/ReadMe.txt", "D:\Files\ReadMe.txt")
End Sub
 
 

Screenshot

The downloaded TXT file

Download Text File (.txt) from URL in ASP.Net using C# and VB.Net
 
 

Downloads