[英]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. 我想下载一个xml文件,但是我在字符串中有一个xml内容。
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, 谢谢,
EDIT Only the first option will work. 编辑只有第一个选项将起作用。 Also, specify a default file name for client: 另外,为客户端指定默认文件名:
return File(Encoding.UTF8.GetBytes(definition), contentType, "somefilename.xml");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.