In this article I will explain with an example, how to download XML file from remote URL in ASP.Net Core MVC.
The XML file will be downloaded from the URL using WebClient class and then will be saved in a Folder (Directory).
The following XML file will be used in this article.
<?xml version="1.0standalone="yes"?>
       <Name>John Hammond</Name>
       <Country>United States</Country>
       <Name>Mudassar Khan</Name>
       <Name>Suzanne Mathews</Name>
       <Name>Robert Schidner</Name>
You will need to import the following namespace.
using System.Net;
The Controller consists of following Action method.
Action method for handling GET operation
Inside this action method, 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.
Note: SecurityProtocol needs to be set to TLS 1.2 (3072) in order to call an API. For more details on SecurityProtocol, please refer my article, Using TLS1.2 in .Net 2.0, .Net 3.0, .Net 3.5 and .Net 4.0.
public class HomeController : Controller
    public IActionResult Index()
        ServicePointManager.Expect100Continue = true;
        ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
        WebClient webClient = new WebClient();
        webClient.DownloadFile("", @"D:\Files\Customer.xml");
        return View();
There is no coding part in View page. Hence, it is skipped.
    Layout = null;
<!DOCTYPE html>
    <meta name="viewport" content="width=device-width" />
The downloaded XML file
ASP.Net Core: Download XML File form URL