DataTable to XML File stored in memory and allow the user to download the XML

137 views Asked by At

I'm attempting to take a DataTable I have of a parsed CSV and turn it into a XML file that a user can download from my web application. All of the solutions I've found so far require me to first write the XML file onto my local drive and then specify the file path for the user to download from.

What I would like to do is have that file created in my controller and then make the output XML file available for download to the user without writing it to a drive.

The code in my controller reads as...

public ActionResult DownloadXML(string url) {
    GetCSVFile newFile = new GetCSVFile();
    DataTable dt = newFile.GetCSV(url); //Gets the remote CSV and parses the data into a DataTable
    DataSet ds = new DataSet();
    ds.Tables.Add(dt);
    ds.WriteXml("myXMLFile.xml");
    return View();
}

I'm also unsure what to use in place of ActionResult. I've looked at FileResult, and FileStreamResult but neither seemed to accomplish what i'm looking for. Any help would be appreciated!

0

There are 0 answers