代码之家  ›  专栏  ›  技术社区  ›  nickytonline

为什么FireFox在下载文件时不包含.xml扩展名?

  •  6
  • nickytonline  · 技术社区  · 16 年前

        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();
    
        }
    

    有人有想法吗?

    3 回复  |  直到 16 年前
        1
  •  8
  •   Jose Gonzalez Jose Gonzalez    16 年前

    尝试更改:

    回应。AddHeader(“内容处理”,“附件;文件名=”+filename);

    回应。AddHeader(“内容处理”,“附件;文件名=”+HttpUtility.UrlEncode(文件名));

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

        2
  •  7
  •   akjoshi HCP    13 年前

    解决了firefox空间问题。 用引号括住文件名。

    更改下面的代码

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

    response.AddHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
    
        3
  •  3
  •   SolutionYogi Eric Lippert    16 年前

    您的文件名中有空格吗?Firefox可能有这个问题。

    http://blog.mjjames.co.uk/2009/04/content-disposition-in-different.html

    推荐文章