点击“打开”按钮后,服务器端响应:
Response.Write( “<script language=javascript>window.open(‘WebForm2.aspx’)</script>”);
WebForm2中:
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
string filePath = Session[“filePath”].ToString();
System.IO.FileStream fs = System.IO.File.OpenRead( filePath );
byte[] FileData = new byte[ fs.Length ];
fs.Read( FileData, 0, (int)fs.Length );
Session.Clear();
Response.Clear();
Response.AddHeader( “Content-Type”, “application/vnd.ms-word” );
Response.AddHeader(“Content-Disposition”, “inline;filename=” + filePath );
Response.AddHeader(“Content-Length”, fs.Length.ToString() );
Response.BinaryWrite( FileData );
fs.Close();
System.IO.File.Delete( filePath );
}
}