国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net上傳下載,自我測試

2024-07-10 13:06:22
字體:
來源:轉載
供稿:網友

using system;
using system.collections;
using system.componentmodel;
using system.data;
using system.drawing;
using system.web;
using system.web.sessionstate;
using system.web.ui;
using system.web.ui.webcontrols;
using system.web.ui.htmlcontrols;
using system.data.sqlclient;
using system.configuration;
using system.io;

namespace sz
{
 /// <summary>
 /// upfile 的摘要說明。
 /// </summary>
 public class upf : system.web.ui.page
 {
  protected system.web.ui.htmlcontrols.htmlinputfile upf1;
  private void page_load(object sender, system.eventargs e)
  {
   

  }
  public void submit_click(object sender,system.eventargs e)
  {
   if(upf1.postedfile.contentlength>0)
   { 
    string[] filesplite = upf1.postedfile.filename.split('//');//取得文件名稱
    string fn = filesplite[filesplite.length -1];
    string ft = upf1.postedfile.contenttype;
    fileinfo fi=new fileinfo(upf1.postedfile.filename);
    filestream fs=fi.openread();
    byte[] bytes=new byte[fs.length];
    fs.read(bytes,0,convert.toint32(fs.length));
    string conn = configurationsettings.appsettings["myconn9"];
    sqlconnection cn = new sqlconnection(conn);
    sqlcommand cm=new sqlcommand();
    cm.connection=cn;
    cm.commandtype=commandtype.text;
    if(cn.state==0) cn.open();
    cm.commandtext="insert into sz_file (filename,filetype,filedata) values ('"+fn+"','"+ft+"',@file)";
    sqlparameter spfile=new sqlparameter("@file",sqldbtype.image);
    spfile.value=bytes;
    cm.parameters.add(spfile);
    cm.executenonquery();
   }
  }
  public void down_click(object sender,system.eventargs e){
   string conn = configurationsettings.appsettings["myconn9"];
   string strsql = "select * from sz_file";
   sqlconnection myconnection = new sqlconnection(conn);
   sqlcommand mycommand = new sqlcommand();
   mycommand.connection = myconnection;
   sqldataadapter objdataadapter = new sqldataadapter();
   objdataadapter.selectcommand = mycommand;
   dataset objectset = new dataset();
   mycommand.commandtext = strsql;
   objdataadapter.fill(objectset,"a");
   datarow dr=objectset.tables["a"].rows[0];
   byte[] file=null;
   file=(byte[])dr["filedata"];
   response.addheader("content-disposition", "attachment;filename="+httputility.urlencode(dr["filename"].tostring(),system.text.encoding.utf8));
   response.contenttype=dr["filetype"].tostring();
   response.binarywrite(file);
  }
  #region web 窗體設計器生成的代碼
  override protected void oninit(eventargs e)
  {
   //
   // codegen: 該調用是 asp.net web 窗體設計器所必需的。
   //
   initializecomponent();
   base.oninit(e);
  }
  
  /// <summary>
  /// 設計器支持所需的方法 - 不要使用代碼編輯器修改
  /// 此方法的內容。
  /// </summary>
  private void initializecomponent()
  {   
   this.load += new system.eventhandler(this.page_load);
  }
  #endregion
 }
}



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 德昌县| 乌兰浩特市| 南充市| 梅州市| 古浪县| 泌阳县| 衡南县| 海晏县| 丹阳市| 霞浦县| 新民市| 锡林浩特市| 威海市| 呼伦贝尔市| 柳江县| 安吉县| 山阳县| 班戈县| 周口市| 绥芬河市| 合阳县| 新晃| 郯城县| 高阳县| 星座| 鹤庆县| 辽宁省| 绥芬河市| 库车县| 霍城县| 宁化县| 临泉县| 张家港市| 龙井市| 星子县| 阆中市| 铜山县| 监利县| 湄潭县| 阳山县| 林州市|