Microsoft MVP성태의 닷넷 이야기
첨부 파일 Download시 한글 Name [링크 복사], [링크+제목 복사],
조회: 16483
글쓴 사람
장근배
홈페이지
첨부 파일
 

안녕하세요,,
여기에 질문을 해도 되는지 모르겠지만 일단 질문을 해 봅니다. ^^;

다름이 아니라 ASPX.NET(2.0)으로 게시판 비슷하게 구성을 하여 Service를 하고 있는데,
첨부 파일을 Download를 하게 되면 file Name이 깨져 나옵니다.
파일을 open, 저장, 취소창에서는 파일 Name이 정상적으로 나오나
해당 파일을 Open을 하게 되면 파일 Name에 '%'가 들어가 있어 이를
저장시 file Name을 다 수정을 해 줘야 합니다.
(저장을 하면 정상적으로 file Name으로 저장이 됩니다)
예를 들어 엑셀 파일 '강아지 List.xls'라고 하면
Open을 하면 Excel의 file Name이 '%ea%b0%95%ec%95%84%ec%a7%80+List.xls' 라고 Display됩니다.
파일을 실제로 download하는 부분은 다음과 같습니다.

Test_FileDown.aspx code
====================================================================================
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test_FileDown.aspx.cs" Inherits="Web_Test.Test_FileDown" %>
=====================================================================================

Test_FileDown.aspx.cs code
====================================================================================
protected void Page_Load(object sender, EventArgs e)
{            
    string _fileName = string.Empty;
    string _filePath = string.Empty;

    int fileNamePoint = 0;
    try
    {
        _filePath = Server.UrlEncode(@"C:\temp\강아지 List.xls");
        _fileName = Server.UrlEncode(@"강아지 List.xls");

        if (null != _filePath && string.Empty != _filePath)
        {
            _filePath = Server.UrlDecode(_filePath);

            if (null == _fileName)
            {
                fileNamePoint = _filePath.Split('\\').Length;
                _fileName = _filePath.Split('\\')[fileNamePoint - 1];
            }
            else
            {
                _fileName = Server.UrlDecode(_fileName);
            }                

            Response.Clear();
            Response.ContentType = "application/Unknown";                    
            Response.AddHeader("Content-Disposition", "attachment;filename=\"" + Server.UrlPathEncode(_fileName).Replace("+", "%20") + "\"");                    
            Response.WriteFile(_filePath);
            Response.Flush();                    
        }
        Response.End();
    }
    catch (Exception ex)
    {
        Response.Clear();
        Response.Write("<script language='javascript'> " +
            " alert('첨부 파일을 다운로드중 오류가 발생하였습니다!'); " +
            " opener = self; " +
            " self.close(); " +
            "</script>");
        Response.End();
    }
}
====================================================================================

web.config code
==================================================================
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
==================================================================

인터넷에서 검색을 해 보아도 결과는 --;;
방법이 있을까요??








[최초 등록일: ]
[최종 수정일: 11/30/2009]


비밀번호

댓글 작성자
 



2009-12-02 10시33분
글쎄요. 제가 보기에도 별로 문제될 것이 없어보이는데요. 제 파일 다운로드 코드 역시 위와 별반 다르지 않습니다. 예를 들어, 이 게시판의 834번 글에 첨부된 파일을 다운로드 받아보세요. (그 파일명이 한글입니다.)

참고로, 제 게시판의 소스 코드는 다음과 같습니다.

Response.Clear();
      Response.ContentType = FileExtension.GetContentType(orgFileName); // "application/octet-stream"
      string encodedFilename = HttpContext.Current.Server.UrlEncode(orgFileName); // orgFileName = "테스트"
      Response.AddHeader("Content-Disposition", "attachment; filename=" + encodedFilename);

      Response.TransmitFile(fullPath);

      Response.End();
kevin25
2011-06-24 05시42분
Response.AddHeader("content-disposition"........Unicode...
; http://forums.asp.net/t/1332340.aspx/1

따라서, 아래와 같이 처리해 보십시오. ^^

string txt = HttpUtility.UrlEncode(fileItem.FileName, System.Text.Encoding.UTF8);
정성태

... 31  32  33  34  35  36  37  38  39  40  41  [42]  43  44  45  ...
NoWriterDateCnt.TitleFile(s)
4801spow...2/3/201710282C#의 참조 동작관련하여 아이디어 문의 드립니다 [4]
4800오세운2/1/201714366C# 에서 C++ DLL임포트 질문입니다. [2]
4798guest1/29/201711693picturebox의 image.dispose [1]
4797김철환1/13/201711657책에 관한 질문입니다 [3]
4796Bere...1/13/201711755++ 후위연산자와 = 을 함께 사용할 때 생성되는 IL 코드 관련... [2]
4795김철환1/11/201712870이벤트 부분을 읽고 있는데 이해가 안되서 질문합니다.. [11]
4794김철환1/10/201710178안녕하세요 c# 6.0 책을 구매한 사람인데요 [3]
4793장준영1/7/201712209안녕하세요 c언어 처음 공부해보는 학생입니다 [4]파일 다운로드1
4792김재영1/4/201713216소스코드 공개 전 성태님의 의견을 듣고싶습니다 [3]
4791C#초보12/28/201613033비동기 소켓 close시 ObjectDisposedException 문제점 질문 있습니다.. [1]
4790미나리12/24/201613289파워포인트 쇼 제어 SimpleHttpServer.cs 작동문제 [4]파일 다운로드1
4789김솔지12/21/201612093프린트 시, 프린트하는 파일의 파일명 구하는 부분에 대해서 질문드립니다. [1]
4788짜두12/19/201611843Visual Studio 2015 에서 msbuild 12 사용 [5]
4787guest12/18/201613631VLC라이브러리에 대해 아시나요? [3]파일 다운로드1
4785Hyou...12/16/201613729WPF 개발 시 MVVM 프레임워크 사용 [2]
4784ds12/15/201610387문의 드립니다. [2]
4783후배12/13/201611982MemoryStream에 관한 질문 입니다. [5]
4782김형민12/6/201610306[ C# 6.0 ] 126p 오타인가요? [6]
4781질문자11/29/201610432ms워드 저장 오류 [1]
4780최진11/28/201614886안녕 하세요 빌드 관련해서 질문드립니다 꾸벅 [4]
4779손니11/28/201611240안녕하세요 질문하다 드려도 될까요 [3]
4778김상호11/25/201610757재귀호출->비재귀호출 [2]파일 다운로드1
4777권오영11/12/201613014아래 질문 상세 소스전체입니다.. [3]
4776권오영11/11/201610910제가 이클립스를 공부중인데..이상한것을 찾았습니다.. [2]
4775이성환11/11/201614386안녕하세요. SnapsToDevicePixels 질문입니다. [5]파일 다운로드1
4774popo11/10/201611005.net SSL통신 관련 질문 드립니다. [1]
... 31  32  33  34  35  36  37  38  39  40  41  [42]  43  44  45  ...