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

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

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

1  2  3  [4]  5  6  7  8  9  10  11  12  13  14  15  ...
NoWriterDateCnt.TitleFile(s)
5894송부장4/14/202315181[질문] Visual Studio 2022에서 '도구 상자 항목 선택'의 'COM 구성 요소' 탭에서 ActiveX 목록이 보이지 않습니다. [3]파일 다운로드2
5893감사합니...4/14/202312697오라클 OLEDB방식 접속 후 SELECT 'TEST' TEST_VALUE FROM DUAL의 값이 이상합니다. [1]
5892한무4/14/202312561C# 으로 백그라운드에서 워드를 실행하여 매크로 실행이 가능 할까요? [2]
5891리세4/14/202314183안녕하세요.C# 서버프로그램에서의 Mysql 쿼리문제(다중쿼리 실행)에 대해 문의드립니다. [2]
5890guest4/14/202315233C# 프리랜서로 돈 벌려면 성태님 책 마스터하면 되나요? [6]
5889전예찬4/14/202312690C# 파일 복사 관련 질문 드립니다. [3]
5888정경구4/12/202312872C# 첫 환경 세팅과 관련해서 [4]
5887HAN4/12/202312964안녕하세요 파이썬도 공유 가능 할까요? [1]
5886guest4/11/202315440필요한 어셈블리만 다운로드 및 재로딩하는 방법에 관하여 [2]
5885guest4/11/202312938c#으로 드림위버같은 거 만들어볼려는데요 [6]
5884궁금이4/11/202313545부모 클래스에서 예외 발생시 힙 영역에 할당 ? [2]
5883코딩초짜4/9/20231296510c언어 usleep 에 대해서 요 [2]
5882조은현4/7/202312406선생님 안녕하세요! wpf의 성능 개선에 대해서 질문드려요! [1]파일 다운로드1
5881guest4/6/202313532static method - <에러메시지 Extension method must be defined in a non-generic static class> [4]
5880유비4/4/202312370WPF DataGrid CollectionView, IEditableCollectionView 관련 문의 [1]
5879guest4/4/202314540Async method의 에러 표시 [3]
5878guest4/3/202314935C#으로 CMOS 설정 변경가능한지요? [4]
5875guest4/2/202315147성태님 책을 완독 하고 Static [7]
5874민성4/1/202313458안녕하세요 질문 하나만 드릴깨요~ [1]
5873guest3/31/202315421제어판에서 삭제불가 MS Edge ---> 레지스트리 편집기에서도 안보임 [6]파일 다운로드1
58723/31/202314393web config 파일 확인부탁드려요 [6]
58713/31/202313414web config 파일 수정이요 [2]파일 다운로드1
5870guest3/30/202313180.NET Core SDK 삭제 시 주의 사항 [4]파일 다운로드1
5869guest3/30/202313822Dictionary의 Update 그리고 Foreach [7]
5868guest3/29/202312872Speech Recognition과 Form1 그리고 정확도 [4]파일 다운로드1
5866월급쟁이3/28/202312655cmake 크로스 컴파일 관련하여 질문이 있습니다 [1]
1  2  3  [4]  5  6  7  8  9  10  11  12  13  14  15  ...