2

I need to download a file as attachment from my server, I get a string, create xml document out of it, and then try to download it, nothing happens. Why is that?

        string xmlTxt= createdXmlString.Str;
        var dir = @"C:\cookieParserXmlOutput\";
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xmlTxt);

        var filePath = Path.Combine(dir, "xmlFile.xml");
        if(!Directory.Exists(dir))
            Directory.CreateDirectory(dir);

        doc.Save(filePath);
        Response.Clear();
        Response.ContentType = "application/octet-stream";
        Response.AddHeader("Content-Disposition", $"attachment; filename={"xmlFile.xml"}");
        Response.TransmitFile(filePath);
        Response.End();

        Response.Close();
Alex
  • 1,982
  • 4
  • 37
  • 70
  • 1
    While not asked the same way, [this answer](https://stackoverflow.com/questions/26038856/how-to-return-a-file-filecontentresult-in-asp-net-webapi) might help you. – Stephan Jun 17 '18 at 08:55

0 Answers0