在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变成我想要的文件的名字???谢谢了先,辛苦各位高手指教,十分谢谢,给您拜个年。
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变成我想要的文件的名字???谢谢了先,辛苦各位高手指教,十分谢谢,给您拜个年。
解决方案 »
- 大家帮我看下,我这样使用Ajax错在哪里
- 高分求解
- 学了ASP.NET,有点郁闷,大家帮忙看看!
- 我定义的用户控件,然后放入了MasterPage里,再根据此MasterPage创建了新的aspx,结果跟踪发现用户控件被加载(Page_Load)了两次,请教一下大
- 再次讨教:从数据访问层到设计层之间的传值问题。
- 关于使用 download.aspx?softid=123 这种格式的用法
- 前台是这样的形式?
- select * into test2 from (exec('select * from table')) as s 问题,是否可以这样
- 经常有人放asp/aspx木马,怎么防这一情况?
- ASP.NET的ImageButton可以直接捕获鼠标的位置?
- dr["biaoti"]?????????
- 急救:我想获得数据库的最新记录,但对于某个字段如果最新十条记录都没有改变则认为无新数据,显示为off.
Response.BinaryWrite( (byte[]) dr["blob"] );这个是写页面的代码,我没有写一个文件,而是直接写到页面上。
Response.AddHeader("Content-Disposition", "attachment;filename=" + ProjectName + ".doc");
//**********************************将整个页面内容导出到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文件。
你存aspx文件流的时候
把“application/ms-word”存入type字段
把你想使用的文件名存入一个filename字段导出文件的时候
...
Response.ContentType=dr["type"].ToString();
Response.AddHeader("Content-Disposition", "attachment;filename=" + dr["filename"].ToString() + ".doc");
...