如果要在IE中開啟的是PDF,excel或者doc格式的檔案,這段程式碼直接就能實現。1 protected void Page_Load(object sender, EventArgs e)2 {3 if (!IsPostBack)4 {5 string fname = Server.MapPath(".") + @"\Files\FarPointOne.doc";6 Response.ClearContent( );7 Response.ClearHeaders( );8 Response.AppendHeader("Content-Disposition", string.Format("inline;filename={0}",fname));9 Response.AppendHeader("content-type", "application/msword");10 Response.WriteFile(fname);11 Response.Flush( );12 Response.Close( );13 }14 } 關於這段程式碼,有一點要注意:content-type 的取值content-type: application/pdf (PDF檔案) || application/msword(WORD檔案) || application/x-msexcel(EXCEL檔案) || text/plain (文字檔案).
如果要在IE中開啟的是PDF,excel或者doc格式的檔案,這段程式碼直接就能實現。1 protected void Page_Load(object sender, EventArgs e)2 {3 if (!IsPostBack)4 {5 string fname = Server.MapPath(".") + @"\Files\FarPointOne.doc";6 Response.ClearContent( );7 Response.ClearHeaders( );8 Response.AppendHeader("Content-Disposition", string.Format("inline;filename={0}",fname));9 Response.AppendHeader("content-type", "application/msword");10 Response.WriteFile(fname);11 Response.Flush( );12 Response.Close( );13 }14 } 關於這段程式碼,有一點要注意:content-type 的取值content-type: application/pdf (PDF檔案) || application/msword(WORD檔案) || application/x-msexcel(EXCEL檔案) || text/plain (文字檔案).