asp.Netはwordをダウンロードする2つの方式を生成します
1337 ワード
word
Response.AddHeader("Content-Disposition", "attachment;filename="
+ HttpUtility.UrlEncode("word .doc", Encoding.UTF8));
Response.ContentType = "application/ms-word";
EnableViewState = false;
var tw = new StringWriter();
var hw = new HtmlTextWriter(tw);
tb1.RenderControl(hw);//tb1 table(div) id
Response.Write(tw.ToString());
Response.End();
word
string sPath = System.IO.Path.GetDirectoryName(this.Page.Request.PhysicalPath);
string a =@"\wendang\ .doc";
string tmpFileName = sPath + a;//@"E:\ \YK_ERP_HNCC\ERPCC\Order\wendang\C++ 04737 2008~2012.doc";
#region
//
FileInfo tmpFI = new FileInfo(tmpFileName);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(Path.GetFileName(tmpFileName), System.Text.Encoding.UTF8));
Response.AppendHeader("Content-Length", tmpFI.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(tmpFileName);
Response.Flush();
Response.End();
//
Response.ContentType = "Application/msword";
Response.WriteFile(tmpFileName);
Response.End();
#endregion
本文は“技術が世界をリードします”のブログから出て、転載をお断りします!