二进制流输出各种类型文件
数据库保存为二进制流,也保存有文件名和后缀名,怎么在web页面输出各种类型的文件。

解决方案 »

  1.   

    Refer:
    http://www.cnblogs.com/insus/articles/2012733.html
      

  2.   

    yte[] filec = (byte[])(ds.Tables[0].Rows[0]["FContent"]);
                Response.Clear();
                string FileName = ds.Tables[0].Rows[0]["FName"].ToString();
                string FullName = ds.Tables[0].Rows[0]["FullName"].ToString();
                //类型
                string imageType = System.IO.Path.GetExtension(FullName).ToLower();
                if (imageType == ".jpg")
                {
                    ResponseEnd(filec, FullName);
                }
                if (imageType == ".doc")
                {
                    ContentType = "application/msword";
                    Response.ContentType = ContentType;
                    Response.ContentEncoding = System.Text.Encoding.Unicode;
                    Response.AddHeader("Content-Disposition ", "attachment;filename=" + FullName);
                    Response.Charset = "GB2312 ";
                    Response.OutputStream.Write(filec, 0, filec.Length);
                    Response.End();
                }
                if (imageType == ".xls")
                {
                    ContentType = "application/vnd.ms-excel";
                    Response.ContentType = ContentType;
                    Response.ContentEncoding = System.Text.Encoding.Unicode;
                    Response.AddHeader("Content-Disposition ", "attachment;filename=" + FullName);
                    Response.Charset = "GB2312 ";
                    Response.OutputStream.Write(filec, 0, filec.Length);
                    Response.End();
                }
                if (imageType == ".pdf")
                {
                    ContentType = "application/pdf";
                    Response.ContentType = ContentType;
                    Response.ContentEncoding = System.Text.Encoding.Unicode;
                    Response.AddHeader("Content-Disposition ", "attachment;filename=" + FullName);
                    Response.Charset = "GB2312 ";
                    Response.OutputStream.Write(filec, 0, filec.Length);
                    Response.End();
                }
     if (imageType == ".pdf")
    或 if (imageType == ".txt")时不显示