Possible Duplicate:
How to download xml file in asp.net using C#
can anyone please help how to download the xml (which is in string).I am using MVC3
Mycode;
public FileResult Download(string id)
{
var model = service.GetAllDefinitions().First(x => x.ID == id);
var definitionDetails = new StatisticDefinitionModel(model);
string xmlString = definitionDetails.ToXml;
//string presented xml
string fileName = definitionDetails.Name + ".xml";
var stream = new MemoryStream();
var writer = XmlWriter.Create(stream);
writer.WriteRaw(xmlString);
stream.Position = 0;
var fileStreamResult = File(stream, "application/xml", fileName);
return fileStreamResult;
}
but this not working.gives an error
Error:
XML document must have a top level element. Error processing resource
Thanks,