为什么FireFox在下载文件时不包括.xml扩展名? [英] Why Does FireFox Not Include the .xml Extension when Downloading a File?

查看:303
本文介绍了为什么FireFox在下载文件时不包括.xml扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的。我确定它下载的XML文件扩展名为.xml,但我想知道这里的代码是什么,导致.xml extenstion从下载的文件丢失。



注意:这适用于IE 6+(没有尝试基于WebKit的浏览器或Opera)

  private void GenerateXmlAttachment(string xmlInStringFormat,string fileName)
{
//其中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();想要任何人吗?

div=h2_lin>解决方案

尝试更改:



response.AddHeader(Content-Disposition,attachment; filename = + fileName);



To:



response.AddHeader(Content-Disposition,attachment; filename =+ HttpUtility.UrlEncode(fileName));



该代码适用于所有浏览器(包括我们大量使用的Firefox)。


OK. I'm sure it does download XML files with the .xml extension, but I'm wondering what is missing in the code here to cause the .xml extenstion to be missing from the downloaded file.

Note: This works in IE 6+ (didn't try WebKit based browsers or 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();

    }

Ideas anyone?

解决方案

Try changing:

response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);

To:

response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName));

The code works for all browsers (including Firefox which we use heavily).

这篇关于为什么FireFox在下载文件时不包括.xml扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆