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

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

다름이 아니라 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);
정성태

... 16  17  18  19  20  21  22  23  24  25  26  [27]  28  29  30  ...
NoWriterDateCnt.TitleFile(s)
5259ming11/13/201914331string타입 파라메터로 넘길때 메모리 내부가 궁금합니다. [3]
5258C#초보11/13/201916148DCOM COM+ 등록 관련 문의드립니다. [7]
5257C#초보11/9/201914330파일 저장 방법에 대해 조언 부탁드립니다. [3]
5256세퉁11/8/201913521안녕하세요~ 질문은 아닙니다만.. [1]
5255C#초보11/6/201914187중첩 딕셔너리를 어떻게 만들 수 있을까요? [2]
5252김동수11/4/201914305Windows 10 로그인 ( Credential Provider ) 문의드립니다. [1]
5251kss11/1/201913971c#문법질문입니다. [1]
5250이대희10/31/201913944시작하세요 C# 7.3 프로그래밍 책이 절판이네요. [1]
5249황태관10/24/201915117c# 폼안에 특정 프로그램 불러오기.. [1]파일 다운로드1
5248황태관10/23/201916414C언어로 만든 dll 를 참조해서 c#으로 만들려면.. [3]
5245민성10/21/201914934안녕하세요 Ui 스레드 접근에 대해서 질문드리도록 하겠습니다. [1]
5244hbli...10/20/201914317두개의 쓰레드에서 하나의 Queue 리스트 사용시 질문드립니다. [2]
5243최선호 donator10/18/201913812Screen Capture 와.. Overlay 질문 좀 드릴게요 ㅠ.ㅠ ( 장문 주의..... ) [2]
5241C#초보10/16/201916299C# USB 통신 구현 관련 질문 드립니다! [1]
5240김동규10/15/201916068런타임 시 Encoding.Default를 UTF-8로 설정할 수 있을까요? [3]
5239밤톨이10/13/201914166시놀리지 DSM에 asp.net core 2 웹서버 구축이 가능한가요? [1]
5238권석헌10/2/201914766C# - C++ 간의 Memorymapped file 관련 Data 질문좀 드립니다 선생님 [1]
5237유호성10/1/201914630사용자 정의 컨트롤 VS IDE에서만 Exception 발생 [2]
5234koko9/25/201916922안녕하세요. 64bit WPF -> 32bit C++ DLL Import사용 문의 드립니다. [3]
5232fox3...9/24/201914351C# Memorymappedfile 재 업로드 드립니다.(실행순서 및 질문내용 정리) [7]파일 다운로드1
5231fox3...9/24/201914466C# 메모리맵드파일 관련 질문드립니다. 최소한의 재현가능코드 첨부후 재질문 드립니다. [2]파일 다운로드1
5230질문9/23/201913946C++ 로 만든 dll 을 C#에서 사용할 때 질문 [2]
5229fox3...9/23/201916715C# 메모리맵드파일 관련 질문드립니다. [2]
5227세퉁9/23/201916005WPF Textblock 폰트 크기에 따라 글자 색이 깨지는 현상이 있습니다. [3]파일 다운로드1
5226김대훈9/23/201914620정말 황당한 경우입니다.. [2]
5223김태균9/19/201914631책 소개 링크가 7.1버전판으로 이어집니다. [1]
... 16  17  18  19  20  21  22  23  24  25  26  [27]  28  29  30  ...