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

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

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

... [76]  77  78  79  80  81  82  83  84  85  86  87  88  89  90  ...
NoWriterDateCnt.TitleFile(s)
636라이프가드4/27/200715869Insert 오류입니다. CLOB ........ [1]
635박희진4/27/200716379스마트클라이언트 위로 DIV가 못올라오고 스마트 클라이언트 뒤로 숨는 현상 [1]
632해운대끓...4/23/200714445이전에 소개 되었던 확장 매서드 아티클을 읽고 생각나는 의문 [1]
620이방은4/18/200717595질문있어요.. [2]
6196/17/200716886Child Form 에서 Mdi Form 의 메소드 Access 방법 [1]
616김우정4/15/200720084CAS 보안설정을 위한 ActiveX 관련 질문입니다 [2]파일 다운로드1
614박성희4/13/200716071IE Embedded된 스마트클라이언트로 로그인 정보를 보내려면 어떻게 해야 되나요? [2]
612김성헌4/11/200718788Vista, ShellExecute(,"runas",) 문제 [1]
611탑~4/10/200714574페이지 치고 들어가는거 막기... [2]
606한귀순4/3/200715920combobox usercontrol [2]
604채영사랑3/29/200716250<질문> System.Runtime.InteropServices.COMException: 개체가 필요합니다. [2]
603근바이3/28/200715818솔루션 -> 구성관리자 [1]
602김성헌3/27/200716361ActiveX 브로커 모듈과 통신방법은 RPC ??
607정성태4/4/200718572    답변글 [답변]: ActiveX 브로커 모듈과 통신방법은 RPC ??
601엔틱스3/22/200716502자동 로그인의 궁금증 [1]
600창민이3/16/200719947ATL 동적조회 관하여... [2]파일 다운로드1
597ygso...3/14/200715345단순 무식한 궁금증.. [1]
596조빵3/14/200715485SmartClient로 사용자PC의 엑셀을 실행시킬수는 없나요? [1]
594ygso...3/13/200716067ClickOnce를 이용하여 SmartClient를 배포할경우.. [2]
589김희택3/2/200714924리소스 추가 방법에 대한 아티클을 보던중에 질문요... [1]파일 다운로드1
588이성진2/24/200717422웹 -> 스마트클라이언트 -> 웹서비스 의 세션 공유 방법 ? [1]
583김영민2/22/200715315Vista에서 "관리자 권한으로 실행"을 통해 실행한 프로세스의 동작
584정성태2/22/200716916    답변글 [답변]: Vista에서 "관리자 권한으로 실행"을 통해 실행한 프로세스의 동작
582한귀순2/22/200715436sqlhelper 의 updatedataset
585정성태2/23/200714710    답변글 [답변]: sqlhelper 의 updatedataset [1]
579futu...2/16/200716075VS2005의 스마트 클라이언트에서 웹브라우저 예제 질문입니다. [1]
... [76]  77  78  79  80  81  82  83  84  85  86  87  88  89  90  ...