작년에도 비슷한 것때문에 질문을 받았는데...
그때도 마무리 짓지 못하고 IE의 문제로 보여진다고만 마무리했었다.

다시금 불거져 나왔다.
이번엔 새로운 증상도 추가되었는데
파일명 자체를 인식못해서 download.aspx라고 파일 저장다이얼로그가 나옴(특정 파일명에 한해서)

고로 뒤벼본결과 역시나 IE6,7의 헤더의 길이(지난번과 동일한 답변)가 지나치게 짧아서..
총 256바이트 중 차떼고 포떼고 하면
파일명으로 사용할수 있는것은 170바이트(글자) 남짓

문젠 아스키로면 170자이다보니
파일명 인코딩을 하면
실제로는 UTF-8의 파일명영역은 1,6,9배(문자의 코드의 영역에따라)로 크기가 늘어나버린다.

아래는 1차 조사때의 보고내용

約款チェック支援システムのファイルのダウンロードにおいてのファイル名切れ問題の調査
タウンロード・プロセスによる文字列(ファイル名)の変化
状態 ファイル名 長さ CharacterSet 総サイズ 制限
アップロード前 あいうえおかきくけこさしすそたち.doc 21 UTF-8 55byte  
アップロード後(サーバー) [12345678]あいうえおかきくけこさしすそたち.doc 31 UTF-8 67byte  
結果ファイル(サーバー) [12345678]あいうえおかきくけこさしすそたち_ref.doc 35 UTF-8 71byte  
結果ファイル(転送中) %5b12345678%5d%e3%81%82%e3%81%84%e3%81%86%e3%81%88%e3%81%8a%e3%81%8b%e3%81%8d%e3%81%8f%e3%81%91%e3%81%93%e3%81%95%e3%81%97%e3%81%99%e3%81%9d%e3%81%9f%e3%81%a1_ref.doc 163 ASCII 163byte キャッシュパスのサイズが255~258(ブラウザによる)バイト以下
結果ファイル(クライアント) 345678]あいうえおかきくけこさしすそたち_ref.doc 32      

Http Header
HTTP/1.1 200 OK
Server: ASP.NET Development Server/8.0.0.0
Date: Thu, 18 Jun 2009 05:26:47 GMT
X-AspNet-Version: 2.0.50727
Content-Disposition: attachment;filename=%5b12345678%5d%e3%81%82%e3%81%84%e3%81%86%e3%81%88%e3%81%8a%e3%81%8b%e3%81%8d%e3%81%8f%e3%81%91%e3%81%93%e3%81%95%e3%81%97%e3%81%99%e3%81%9d%e3%81%9f%e3%81%a1_ref.doc
Cache-Control: private
Content-Type: application/unknown; charset=utf-8
Content-Length: 326

文字の変換
文字 CharacterSet 一文字のサイズ 長さ 総サイズ
UTF-8 1~4バイト(可変) 1 3バイト
%E3%81%82 ASCII 1バイト 9 9バイト

UTF-8の規格
長さ 対象 サイズ
一桁 ASCII 1バイト
二桁 記号(ヨーロッパ文字) 6バイト
三桁 日本語、韓国語、中国語など 9バイト
四桁   12バイト

암튼 아래 내용은 한글 관련이지만 어차피 비슷한 내용
http://www.hoons.kr/board.aspx?Name=QAASPNET&Mode=2&BoardIdx=3590&Key=&Value=

이건 마소의 서포트 내용 
http://support.microsoft.com/kb/436616/ja 

위의 내용에 실린 globalization을 설정해보았지만 역시나 해결불가..

인코딩후의 길이가 170 이상이면 zip압축으로 대체로 가닥을 잡았다.
AND

구 소스를 활용하여 UI를 변경하던중
중요한 사항을 빠뜨려먹고 잠시 헤멘고로 적어놓음

FileUpload콘트롤은 Async Postback으론 포스트된 파일에 접근하지 못한다.
고로 UpdatePanel의 트리거에 FileUpload콘트롤을 Postback Control로 등록을 해주어야함!!!

추가로 자바스크립트에서 파일명에 접근할땐,
Value로..

내 머리는 휘발성 메모리.. ㅠ_ㅠ
AND

Chrome의 버그(?)

WEB/ASP.NET 2008. 11. 11. 11:23
ASP.NET의 AutoPostBack의 자바스크립트가 Chrome에서 오동작 하는 사례가 발견됨..
내가 만든 소스의 경우 asp:ListItem(HTML의 SELECT)의 selectedIndex가 바뀔때 마다 PostBack을 하도록 작성되었는데..
Chrome은 해당 자바스크립트의 매개변수인 이벤트(evt)가 정의 되어있지않다고 에러가 뜨며(라곤해도 디버거를 봐야만 보임) 동작하지 않음

관련된(과연?) 포스트
validation 문제라는데..
http://weblogs.asp.net/stefansedich/archive/2008/11/04/bug-with-latest-google-chrome-and-asp-net-validation.aspx
AND

다중 업로드

WEB/ASP.NET 2008. 5. 28. 16:43
티스토리식 다중업로드를 찾다가 알게된녀석
그나마 코드 프로젝트중 제일나은듯
http://www.codeproject.com/KB/aspnet/FlashUpload.aspx

플래시를 이용한 업로드이고 화면도 깔끔에 플래시 소스도 공개..
좋아 >_<

사용자 삽입 이미지
사용자 삽입 이미지

음냐냐 그나저나 적용 가능하려나..
플래시에서 데이터 받아오기 지롤인데 ㅠ_ㅠ

*추가
라고 적고보니 이넘은 플렉스 버전이다 =.=
Flex2.0SDK받아서 수작업으로 고쳐서 사용중...
* 요건 상용
http://ajaxuploader.com/
사용자 삽입 이미지

AND

하나의 모달팝업에 여러개의 취소버튼 넣기..
자바스크립트를 이용한 고스트스텝(?) ㅋㅋ
http://mattberseth.com/blog/2007/10/modalpopup_with_multiple_cance.html
AND

System.Web.HttpResponse objResponse = System.Web.HttpContext.Current.Response;

   objResponse.ClearContent();
   objResponse.ClearHeaders();
   objResponse.ContentType = "application/vnd.msexcel";
   objResponse.AddHeader("content-disposition", "attachment; filename=SearchResults.xls");
   objResponse.AppendHeader("Content-Length", result.Length.ToString());
   objResponse.Charset = "euc-kr";
   objResponse.ContentEncoding = Encoding.GetEncoding(949);
   objResponse.Write(result);
   objResponse.Flush();
   objResponse.Close();
   objResponse.End();

예제는 엑셀 데이터를 다운로드 하는 경우이다. result string 에는 탭으로 분리된 텍스트를 넣어주면 xls파일로 다운로드 된다. 정식 엑셀 파일은 아니고 csv를 xls 확장자로 다운로드 하면 나머지는 엑셀이 알아서 한다. 푸른색으로 된 부분은 한글 코드 문제로 넣어 준것이다. 그냥 Unicode로 보내면 엑셀이 제대로 처리하지 못한다. 이유는 모르겠다.

출처 : http://www.code99.net/Default.aspx?tabid=794&EntryID=186

Exporting DataGrid to Excel

Exporting DataGrid to Excel might sound complex but it's pretty simple. Let's see how this can be done.

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.xls");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.xls";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

The code given above is the complete code to export a DataGrid to an Excel file:

  • Response.AddHeader is letting ASP.NET know that we are exporting to a file which is named FileName.xls.
  • Response.ContentType denotes the type of the file being exported.
  • myDataGrid.RenderControl(htmlWrite) writes the data to the HtmlTextWriter.
  • Response.Write(stringWrite.ToString()); sends the request to the response stream.

As you can see, exporting a DataGrid to an Excel file is pretty simple.

Exporting the DataGrid to a Word file

You can also export a DataGrid to a Word file. You might ask a question that why would anyone like to do that. If you have a Word document which needs a table, then you can simply export the table from the DataGrid to the Word document. The code is similar to the above with minor changes.

Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=FileName.doc");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.word";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

myDataGrid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();

Exporting a DataGrid to a Text File

Sometimes you need to export a DataGrid to a Text file. In this case you need to iterate through the DataSet and concatenate the text to a string or more precisely a StringBuilder object. Let's see how this can be done:

Collapse
Database db = DatabaseFactory.CreateDatabase();
DBCommandWrapper selectCommandWrapper = 
   db.GetStoredProcCommandWrapper("sp_GetLatestArticles");
DataSet ds = db.ExecuteDataSet(selectCommandWrapper);
StringBuilder str = new StringBuilder();

for(int i=0;i<=ds.Tables[0].Rows.Count - 1; i++)
{
  for(int j=0;j<=ds.Tables[0].Columns.Count - 1; j++)
  {
      str.Append(ds.Tables[0].Rows[i][j].ToString());
  }

  str.Append("<BR>");
}

Response.Clear();
Response.AddHeader("content-disposition", 
         "attachment;filename=FileName.txt");
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.text";

System.IO.StringWriter stringWrite = new System.IO.StringWriter();
System.Web.UI.HtmlTextWriter htmlWrite = 
              new HtmlTextWriter(stringWrite);

Response.Write(str.ToString());
Response.End();

The important thing to note is the two for loops that iterate through the DataSet and append the rows into the StringBuilder object.

Format Issue when Exporting DataGrid to Excel

I would like to thank Sonu Kapoor for helping me with the Format issue in exporting a DataGrid to Excel and Juss for providing the code.

When you export a DataGrid to Excel it loses its format. This means that maybe your DataGrid has a string field which consisted of numbers, say '002345'. But when you export the grid and see it in an Excel file you will find that the number changed to '2345'.

You can solve this problem using Cascading Style Sheets.

Code provided by Juss:

Dim strFileName, strFilePath AsString
Dim oStringWriter AsNew System.IO.StringWriter
Dim oHtmlTextWriter AsNew System.Web.UI.HtmlTextWriter(oStringWriter)
Dim objStreamWriter As StreamWriter
Dim strStyle AsString = "<style>.text { mso-number-format:\@; } </style>"
objStreamWriter = File.AppendText(strFilePath)
DataGrid1.RenderControl(oHtmlTextWriter)
objStreamWriter.WriteLine(strStyle)
objStreamWriter.WriteLine(oStringWriter.ToString())
objStreamWriter.Close()

Most of you might be thinking about that "mso-number-format" stuff in between the code. This is the style in which the column will be exported. For this reason, you need to inject the attribute into the DataGrid column for which you want to change the display format.

DataGrid1.DataBind()
Dim strStyle AsString = "<style>.text { mso-number-format:\@; } </style>"
For intTemp AsInteger = 1 To ds.Tables(0).Rows.Count - 1
   DataGrid1.Items(intTemp).Cells(0).Attributes.Add("class", "text")
Next

You can export in many formats. All you need to know is the mso-number-format:\@;. You can easily find the format by opening an Excel file and typing a number in one of the cells. Now if you want to save this number as a Social Security Pattern (xxx-xx-xxxx), right click on the cell and select a pattern that saves it as a Social Security Number. Next save the Excel file to XML format. Open the XML file in Notepad and see what style the column SSN uses. The SSN style is something like this: mso-number-format:000\-00\-0000.

Simply substitute the new style in the strStyle variable and that's it.

For a complete discussion on this issue, please visit this link.

I hope you liked the article, happy coding!

출처 : http://blog.naver.com/jjigye/30012879332

AND