Ash
Ash

Reputation: 220

How to Download a xml content to a file

i want to download a xml file,but i have a xml content in a string.

 public FileResult Download(string id)//guid
    {
        string fid = Convert.ToString(id);

        var model = service.GetAllDefinitions().First(x => x.ID == id);            
        var definitionDetails = new StatisticDefinitionModel(model);
        var definition = definitionDetails.ToXml;
         //in this definition i have xml content not a path
        string fileName = definitionDetails.Name + ".xml";
        string contentType = "text/xml";

        return File(definition , contentType);
    } 

but this is not working,got error like illegal path.

Thanks,

Upvotes: 0

Views: 442

Answers (1)

Marcelo De Zen
Marcelo De Zen

Reputation: 9497

EDIT Only the first option will work. Also, specify a default file name for client:

 return File(Encoding.UTF8.GetBytes(definition), contentType, "somefilename.xml");

Upvotes: 1

Related Questions