Response.AddHeader("Content-disposition", "attachment; filename=" + 文件名);
Response.Write(数据);

解决方案 »

  1.   

    <%@Page language="C#"%>
    <%@import namespace="System.Data"%>
    <%@import namespace="System.Data.SqlClient"%>
    <script language="C#" runat="server">
    public void Page_Load(Object o, EventArgs e)
    {
    int ImgID = Convert.ToInt32(Request.Params["id"]);
    string connStr = ConfigurationSettings.AppSettings["ConnectionString"];
    SqlConnection conn = new SqlConnection(connStr);
    string sql = "select * from t_imgs where id = @ImgID";
    SqlCommand cmd = new SqlCommand(sql, conn);
    cmd.Parameters.Add("@ImgID", SqlDbType.Int).Value = ImgID;
    conn.Open();
    SqlDataReader read = cmd.ExecuteReader();
    read.Read();
    Response.ContentType = (string)read["type"];
             string strFileName = System.Web.HttpUtility.UrlEncode( System.Text.Encoding.UTF8.GetBytes((string)read["imgName"]);
             Response.AppendHeader("Content-Disposition", "attachment; filename=" + strFileName);
             Response.ContentType = "application/octet-stream";
    Response.BinaryWrite((byte[])read["imgData"], 0, (int)read["imgSize"]);
    Response.End();
    conn.Close();
    }
    </script>
      

  2.   

    我是读数据库中的二进制流出来波, uno(钢盅郭子) 这样可行吗?
      

  3.   

    文件下载
    用aspx读取文件输出它
    string strFile = "e:\\test.doc";
    FileStream fs = new FileStream(strFile, FileMode.Open);
    byte[] bytes = new byte[(int)fs.Length];
    fs.Read(bytes, 0, bytes.Length);
    fs.Close();
    Response.ContentType = "application/octet-stream";
    Response.AddHeader("Content-Disposition", "attachment;filename=" & strFile);
    Response.BinaryWrite(bytes);
    Response.End();
      

  4.   

    文件上传参考:http://www.chinabs.net/aspnet/default.asp?infoid=100
      

  5.   

    SqlDa.SelectCommand.CommandText = "select * from itemcontent where icid=" + id
            SqlDa.SelectCommand.Connection = Conn
            SqlDa.Fill(DsContent1, "ic")        Dim dr As SqlClient.SqlDataReader = SqlDa.SelectCommand.ExecuteReader
            dr.Read()        '数据为空退出
            If dr.IsDBNull(9) Then
                Response.Write("<script language='JavaScript'>alert('没有文件信息');</script>")
                Response.Write("<script language='JavaScript'>window.close();</script>")
                Exit Sub
            End If
            '读取数据
            Dim TrueSize = dr.GetBytes(fileDataCol, 0, Nothing, 0, Integer.MaxValue)
            Dim fileContent(TrueSize) As Byte
            dr.GetBytes(fileDataCol, 0, fileContent, 0, TrueSize)        '将变量设置为实际读取的长度
            Response.ContentType = DsContent1.Tables("ic").Rows(0).Item("filetype")
            Response.AddHeader("Content-Disposition", "attachment; filename=" + DsContent1.Tables("ic").Rows(0).Item("filename"))
            Me.Response.Clear()
            Dim fs As System.IO.Stream = Me.Response.OutputStream
            fs.Write(fileContent, 0, fileContent.Length)
            fs.Close()
            Response.End()
      

  6.   

    呵呵,我要的是Asp.net之C#篇的,谢谢!我也试了,可是我不知道问题出在哪了就是不弹出窗口问问我是否下载还是直接打开啊!