개발

[.net] IE에서 한글이름으로 된 파일 다운로드 시 오류발생 (크롬 정상 다운로드 가능)

지승준 2014. 5. 14. 14:19
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class gadmin_download_download: System.Web.UI.Page {
 
    protected void Page_Load( object sender, EventArgs e ) {
 
        string path = Server.MapPath( "." );
        string filename = HttpUtility.UrlDecode( Request.QueryString[ "strFile" ] );
        string endcode_filename = string.Empty;
 
        if( Page.Request.UserAgent.IndexOf( "NT 5.0" ) >= 0 ) {
            endcode_filename = Server.UrlEncode( filename );
        } else {
            endcode_filename = HttpUtility.UrlEncode( filename, new UTF8Encoding() ).Replace( "+""%20" );
        }
 
        Response.AddHeader( "Content-Disposition""attachment;filename=" + endcode_filename );
        Response.ContentType = "application/octet-stream";
        Response.HeaderEncoding = Encoding.GetEncoding( "utf-8" );
        Response.WriteFile( path + @"\" + filename );
 
    }
 
}
cs