从数据库读出word然后IE打开

来源:互联网 发布:手游倩女幽魂辅助软件 编辑:程序博客网 时间:2024/06/04 18:25

string fileid = Request["file_id"].ToString();

   try
   {
    SZPOA.Biz.PublicPOA myclass = new SZPOA.Biz.PublicPOA();    
    if (myclass.GetFile_nolr(Request["file_id"].ToString()) != null)
    {
     byte[] File =myclass.GetFile_nolr(Request["file_id"].ToString());
     FileStream fs;
     FileInfo fi=new System.IO.FileInfo("d://" + fileid + "pcword.doc");
     fs=fi.OpenWrite();
     fs.Write(File,0,File.Length);
     fs.Close();
    }
    else
    {
     SiteClass.MessageBox.ShowOther(this,"对不起,数据库中未找到文件内容!");
    }
   }
   catch
   {
    MessageBox.ShowOther(this,"从数据库读取Word文档出错!");
   }  

FileStream file = System.IO.File.OpenRead("d://" + fileid + "pcword.doc");
   BinaryReader bin = new BinaryReader(file);
   byte[] bytes = bin.ReadBytes((int)file.Length);
   Response.AddHeader( "content-type","application/msword") ;
   Response.AddHeader(  "Content-Disposition","attachment;filename=temp.doc");
   Response.BinaryWrite(bytes);

原创粉丝点击