문제

현재 ASP .NET 응용 프로그램에 Visual Studio 2008을 사용하고 있습니다. 응답 객체를 통해 Excel 파일을 서버하려고합니다. 문제는 파일 제목을 일본어로 설정할 수 없다는 것입니다. 일본어 파일 이름으로 설정하면 쓰레기 문자로 반환됩니다. 일본식 WinXP에서 일본어 브라우저를 사용하고 있습니다.

Response.AppendHeader("Content-Type", "application/vnd.ms-excel");
Response.AddHeader("Content-Disposition", String.Format("attachment; filename=\"{0}\"", "日本語.xls"));

또는

Response.AddHeader("Content-Disposition", String.Format("attachment; filename=\"{0}\"", Server.HtmlEncode("日本語.xls")));

이미 인코딩을 Shift-JI로 변경하려고했습니다

Response.Charset = "Shift_JIS";

또는

Response.Charset = "sjis";

어떤 아이디어? BTW, 나는 Visual Studio 2005 와도 같은 문제가있었습니다.

도움이 되었습니까?

해결책

저는 ASP 전문가가 아니지만 Urlencode를 사용하여 파일 이름을 다시 코딩해 보셨습니까?

Response.AddHeader("Content-Disposition",
    System.Web.HttpUtility.UrlEncode(String.Format("attachment; filename=\"{0}\"", "日本語.xls")));

다른 팁

Response.Charset HTTP 요청의 본문에만 관심이 있습니다. 에 따르면 HTTP 사양, 헤더는 ISO-8859-1로 암시 적으로 인코딩됩니다. 마임 인코딩.

이것은 단지 논리적입니다 - 결국, 바디 인코딩은 Response.Charset 자체는 헤더에 지정됩니다.

나는 그것을 작동시켰다. 드디어 ... :)

사용 System.Web.HttpUtility.UrlPathEncode 쓰레기 문제를 해결하지만 파일을 열면 실제 일본어 문자 대신 파일 이름에 유니 코드로 배달 된 이름을 표시합니다.

따라서 사용하는 대신 System.Web.HttpUtility.UrlPathEncode 응답 헤더에 사용 된 인코딩을 사용하여 파일 이름을 디코딩해야합니다.

.NET에서, 기본적으로 응답 헤더의 인코딩은 UTF-8이고 ISO-8859-1로 변경하십시오. 아래와 같이 Web.config를 수정하십시오.

<globalization responseHeaderEncoding="iso-8859-1" .../>

코드는

    //apply Response header's encoding i.e. iso-8859-1 to the filename.
    Dim fileName as String = "在庫あり全商品を24時間以内に出荷.doc" 
    Dim enc As Encoding = Encoding.GetEncoding("shift_jis") 
    Dim dec As Encoding = Encoding.GetEncoding("iso-8859-1")
    fileName = dec.GetString(enc.GetBytes(fileName))

    //Show Download Dialog box and Writting it on Client Side.
    Response.ClearHeaders() 
    Response.ContentType = corspBean.ContentType 
    Response.AppendHeader("content-disposition", "attachment; filename=""" + fileName + """") 
    Response.BinaryWrite(bytes) 
    Response.End()

이제 한 가지 더 중요한 것은, 나는 그것 때문에 많은 시간을 낭비했습니다. ASP.NET Development Server에서는 작동하지 않습니다 즉, 로컬 컴퓨터에서 웹 앱을 테스트/디버깅하는 데 사용하는 서버. 따라서 IIS에 솔루션을 배포하고 거기에서 테스트하십시오. IIS에서 완벽하게 작동합니다. (및 IIS는 모든 ASP.NET 앱의 운명입니다.) 따라서 ASP.NET Development Server에서 작동하는지 여부는 중요하지 않습니다)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top