Stangray
SAP THQ Apple Nintendo Google Reynolds Amazon Yahoo

发现很多园子里的人在处理Response 下载文件名是使用这个方法

Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileInfo.Name, System.Text.Encoding.UTF8));

但这个只是针对没有空格和IE的情况下使用。

如果想在FireFox下输出没有编码的文件,并且IE下输出的文件名中空格不为+号,就要多一次判断了。

                        if (Request.UserAgent.ToLower().IndexOf("msie") > -1)
                        {
                            downloadfilename = HttpUtility.UrlPathEncode(downloadfilename);
                        }

                        if (Request.UserAgent.ToLower().IndexOf("firefox") > -1)
                        {
                            Response.AddHeader("Content-Disposition", "attachment;filename=\"" + downloadfilename + "\"");
                        }
                        else
                        {
                            Response.AddHeader("Content-Disposition", "attachment;filename=" + downloadfilename);
                        }

posted on 2010-06-28 17:13  Stangray  阅读(9260)  评论(0编辑  收藏  举报