网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > ASP.NET应用
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.ADO.NET和LINQ中古怪的事务特性.
.使用ADO.NET2.0提升数据交互性能.
.使用 DataAdapter 执行批量更新.
.深入分析ADO.NET中的DataSet对象.
.使用ADO.NET2.0提升数据交互性能.
.使用ADO.NET2.0提升数据交互性能.
.Ado.net快马加鞭.
.ADO.NET中的视图和过滤器.
.深入解读 ADO.NET2.0的十大最新特.
.ADO.NET 数据集中浏览多个相关表.
.ADO.NET中的多数据表操作浅析之读.
.通过DataTable获得表的主键.
.通过ADO.NET实现事务处理.
.亲密接触ADO.NETv2.0.
.ADO.net中数据库连接方式.
.ado.net数据库连接.
.在VB.NET中使用MS Access存储过程.
.ADO.NET起步.
.NHibernate与Ado.Net查询速度的比.
.使用ADO.net将数据导出到Excel并.

用ado.net对word,excel进行存取

发表日期:2005-2-5


blob表

3 id int 4 0
0 name char 50 1
0 blob image 16 1
0 type char 60 1

saveFile.aspx.cs

  private void Button1_Click(object sender, System.EventArgs e)
  {
   Stream imgdatastream = File1.PostedFile.InputStream;
   int imgdatalen = File1.PostedFile.ContentLength;
   string imgtype = File1.PostedFile.ContentType;
   string name = this.getFileNameByURL(this.File1.PostedFile.FileName);
   byte[] imgdata = new byte[imgdatalen];
   int n = imgdatastream.Read(imgdata,0,imgdatalen);
   string connstr =  "workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
   SqlConnection connection = new SqlConnection(connstr);
   SqlCommand command = new SqlCommand("INSERT INTO blob(name,type,blob)  VALUES ( @imgtitle, @type,@blob )", connection );
   SqlParameter paramTitle = new SqlParameter("@imgtitle", SqlDbType.VarChar,50 );
   paramTitle.Value = name;
   command.Parameters.Add(paramTitle);
   SqlParameter paramData = new SqlParameter( "@blob", SqlDbType.Image );
   paramData.Value = imgdata;
   command.Parameters.Add( paramData );
   SqlParameter paramType = new SqlParameter( "@type", SqlDbType.VarChar,50 );
   paramType.Value = imgtype;
   command.Parameters.Add( paramType );
   wztj.debug.TestSQL.TraceErrorSql("INSERT INTO blob(name,type,blob)  VALUES ( @imgtitle, @type,@blob )",command.Parameters);
   connection.Open();
   int numRowsAffected = command.ExecuteNonQuery();
   connection.Close();
  }

listFile.aspx//这个东西主要用来列表,把已经有的东西列出来

<asp:HyperLinkColumn DataNavigateUrlField="id" HeaderText="产品名称" DataNavigateUrlFormatString="./getFile.aspx?ID={0}" DataTextField="name" DataTextFormatString="{0}" ItemStyle-HorizontalAlign="Center" ItemStyle-Width="160px">

listFile.aspx.cs

   string connstr="workstation id=OVERMIND;packet size=4096;user id=sa;password=sa;data source=OVERMIND;persist security info=False;initial catalog=wztj";
   SqlConnection connection = new SqlConnection(connstr);
   SqlCommand command = new SqlCommand("select * from blob", connection );
   connection.Open();
   SqlDataAdapter adaptor = new SqlDataAdapter(command);
   DataSet ds = new DataSet();
   adaptor.Fill(ds,"blob");
   connection.Close();
   this.DataGrid1.DataSource=ds.Tables["blob"].DefaultView;
   this.DataGrid1.DataBind();

getFile.aspx.cs//这个文件比较重要负责把村道数据库里面的文件,按照格式,按照名称,给传输出来

  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.Clear();
    Response.Buffer= true;
    Response.Charset="GB2312";   
    Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
    //Response.ContentType = "application/ms-word";//设置输出文件类型为word文件。
    Response.ContentType = dr["type"].ToString();
    Response.BinaryWrite( (byte[]) dr["blob"] );
    string FileName = dr["name"].ToString().Trim();
    FileName=System.Web.HttpUtility.UrlEncode(FileName,System.Text.Encoding.UTF8 );
    Response.AppendHeader("Content-Disposition", "attachment;filename="+FileName);
   }
   connection.Close();
  }


这里要说的有两点,第一,就是把文件的名称getFile.aspx变成我们想要的名称。

 Response.AppendHeader("Content-Disposition", "attachment;filename="+FileName);

第二,就是把指定的名称变成我们想要的值,是标准的中文,而不是中文的乱码。

 FileName=System.Web.HttpUtility.UrlEncode(FileName,System.Text.Encoding.UTF8 );

上一篇:深入解读 ADO.NET2.0的十大最新特性 人气:13794
下一篇:深入分析ADO.NET中的DataSet对象 人气:18726
浏览全部ado.net的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐