好。 我敢肯定,这确实下载扩展名为.xml的XML文件,但我想知道什么是在代码所缺少这里引起.XML extenstion从下载的文件丢失。
注意:这适用于IE 6+(没有尝试基于WebKit的浏览器或Opera)
private void GenerateXmlAttachment(string xmlInStringFormat, string fileName)
{
// Where fileName = "someFile.xml"
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.Charset = string.Empty;
response.ContentEncoding = Encoding.Default;
response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
response.AddHeader("Content-Length", xmlInStringFormat.Length.ToString());
response.ContentType = "text/xml";
response.Write(xmlInStringFormat);
response.Flush();
response.End();
}
想法吗?