當我傳遞文件名時,我將一個數據表導出爲單詞,但似乎並未在「打開/保存」對話框中獲取文件名。導出爲帶有文件名的文字似乎不起作用
下面是我在做什麼
public static void Convertword(DataTable dt, HttpResponse Response,string filename)
{
try
{
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 System.Web.UI.HtmlTextWriter(stringWrite);
System.Web.UI.WebControls.GridView dg = new System.Web.UI.WebControls.GridView();
dg.DataSource = dt;
dg.DataBind();
dg.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();
}
catch(Exception err)
{
throw err;
}
}
當我通過文件名"report(" + System.DateTime.Now.ToString("dd/MM/yyyy"); + ")"
它沒有考慮的價值爲DD/MM/YYYY相反,它顯示的文件名作爲dd_MM_YYYY
所以,問題是去文件保存對話框說的不是「DD/MM/YYYY」或問題「dd_MM_yyyy」它說別的(如我的空間。 ASPX)? 如果你想發送一個實際的Word文件,你應該使用一些庫來寫入Word文件並寫入響應輸出流(它發送字節) – helios 2009-12-29 10:16:37