我上传的文件,但是在浏览时,我想让它弹出对话框提示打开还是保存,我现在的程序是在浏览器上直接打开了,有的文件在浏览器中打开是浏览不了的

解决方案 »

  1.   

    "我想让它弹出对话框提示打开还是保存"
    当使用Response.BinaryWrite打开文件时,就会弹出对话框提示打开还是保存!
    如下:打开一个存储在数据库image字段的doc文档,
    sqlConnection1.Open();
    int id = 5;
    sqlCommand1.Connection = sqlConnection1;
                sqlCommand1.CommandText = "select * from ImageStore where ImageId = "+ id ;
    sqlDataAdapter1.SelectCommand =  sqlCommand1;
    sqlDataAdapter1.Fill(dataSet11,"ImageStore");
    string FileName = "Temp.doc";
    Response.AddHeader("Content-Disposition", "attachment;FileName=" + System.Web.HttpUtility.UrlEncode(FileName));//System.Web.HttpUtility.UrlEncode(System.Text.Encoding.Default.GetBytes( FileName)));
    Response.Charset ="GB2312";
    Response.ContentEncoding =System.Text.Encoding.GetEncoding("GB2312"); 
    Response.ContentType = dataSet11.Tables["ImageStore"].Rows[0]["ImageContentType"].ToString();
    Response.BinaryWrite((Byte[])dataSet11.Tables["ImageStore"].Rows[0]["ImageData"]); sqlConnection1.Close();