In this article I will explain with an example, how to download XML file from URL in C# and VB.Net.
In this Windows Forms application, the XML file will be downloaded from the URL using WebClient class and then will be saved in a Folder (Directory) using C# and VB.Net.
The following XML file will be used in this article.
<?xml version="1.0" standalone="yes"?>
       <Name>John Hammond</Name>
       <Country>United States</Country>
       <Name>Mudassar Khan</Name>
       <Name>Suzanne Mathews</Name>
       <Name>Robert Schidner</Name>
Form Design
Following is the Form.
Download XML File from URL in C# and VB.Net
You will need to import the following namespace.
using System.Net;
Imports System.Net
Downloading XML File from URL
Inside the Form Load event handler, the XML 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.
protecte dvoid Form_Load(object sender, EventArgs e)
    ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
    WebClient webClient = new WebClient();
    webClient.DownloadFile("", @"D:\Files\Customers.xml");
Protected Sub Form_Load(sender As Object, e AsEventArgs) Handles MyBase.Load
    ServicePointManager.Expect100Continue = True
    ServicePointManager.SecurityProtocol = CType(3072, SecurityProtocolType)
    Dim webClient As WebClient = New WebClient()
    webClient.DownloadFile("", "D:\Files\Customers.xml")
End Sub
The downloaded XML file
Download XML File from URL in C# and VB.Net