You don't need an xml stream here, just return the bytes.
public FileResult Download(string id) { var model = service.GetAllDefinitions().First(x => x.ID == id); var definitionDetails = new StatisticDefinitionModel(model); string xmlString = definitionDetails.ToXml; string fileName = definitionDetails.Name + ".xml"; return File(Encoding.UTF8.GetBytes(xmlString), "application/xml", fileName); }
source share