在sql server
3 id int 4 0
0 name char 50 1
0 blob image 16 1
0 type char 60 1把文件存好之后,输出的时候用一个getFile.aspx private void Page_Load(object sender, System.EventArgs e)
{
string imgid =this.Request.QueryString.Get("ID");
//Request.QueryString["imgid"]; 
string connstr="workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
string sql="SELECT name,blob, type FROM blob WHERE id = " + imgid; 
SqlConnection connection = new SqlConnection(connstr); 
SqlCommand command = new SqlCommand(sql, connection);
connection.Open(); 
SqlDataReader dr = command.ExecuteReader(); 
if(dr.Read()) 
{
Response.ContentType = dr["type"].ToString(); 
Response.BinaryWrite( (byte[]) dr["blob"] );
//Page.ResolveUrl(dr["name"].ToString());
//Response.

connection.Close(); 
}
把这个东西输出出来,然后在外面调用
getFile.aspx?ID=1这时候可以输出,输出的东西默认叫做getFile.aspx,应该改成1.doc,但是我不知道怎么改。问题就是怎么把输出的文件名字getFile.aspx变成我想要的文件的名字???谢谢了先,辛苦各位高手指教,十分谢谢,给您拜个年。

解决方案 »

  1.   

    Response.ContentType = dr["type"].ToString(); 
    Response.BinaryWrite( (byte[]) dr["blob"] );这个是写页面的代码,我没有写一个文件,而是直接写到页面上。
      

  2.   

    try it, plz~~            Response.ContentType = "application/vnd.ms-word";
                Response.AddHeader("Content-Disposition", "attachment;filename=" + ProjectName + ".doc");
      

  3.   

    把*.aspx 文件导出到Doc文件中是可以的 //ExportToWord();
    //**********************************将整个页面内容导出到Word中
    Response.Clear(); 
    Response.Buffer= true; 
    Response.Charset="GB2312";    
    Response.AppendHeader("Content-Disposition","attachment;filename=FileName.doc"); 
    Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
    Response.ContentType = "application/ms-word";//设置输出文件类型为word文件。
      

  4.   

    Try;
    你存aspx文件流的时候
    把“application/ms-word”存入type字段
    把你想使用的文件名存入一个filename字段导出文件的时候
      ...
      Response.ContentType=dr["type"].ToString();
      Response.AddHeader("Content-Disposition", "attachment;filename=" + dr["filename"].ToString() + ".doc");
      ...