I have a method to create an XML File and save it to the desired file path. It works perfectly. But the problem I am facing is I have to allow the user to download this file but it gets downloaded to the server on the given file path, not on the user's system.
I have the following code for the same
var dateString1 = DateTime.Now.ToString("yyyyMMddHHmmss");
XmlWriterSettings settings = new XmlWriterSettings
{
Indent = true,
IndentChars = (" "),
ConformanceLevel = ConformanceLevel.Fragment,
CloseOutput = true,
OmitXmlDeclaration = true
};
using (XmlWriter writer = XmlWriter.Create(filePath + "bill" + dateString1 + ".xml", settings))
{
writer.WriteStartElement("HEADER");
.......Some more Code..............
writer.WriteEndElement(); //HEADER
writer.Flush();
}
return Json(1, JsonRequestBehavior.AllowGet);
I need the file generated to be downloaded on the user's system automatically when he requests it and there is no other file generated.
Thank you.