发布网友 发布时间:2022-04-25 23:43
共4个回答
热心网友 时间:2023-05-08 00:36
。* 我修改了m一b天z时间。终于e找到门e路了d。呵呵 ACCESS中8存放文2件内4容的字段类型为5:OLE对象 SQL中0存放文5件内4容的字段类型为1:image 此代码为3上o传文1件代码。梢后整理发布下s载文8件代码 代码设计2实现功能:asp。NET上d传文6件到指定文5件夹,ACCESS数据库,SQL数据库代码 已b经测试文0件格式 。TXT,JPG。。MDB。GIF *。 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。IO; using System。Data。OleDb; using System。Data。SqlClient; namespace WebApplication7。ManageFile { 。。。 <summary> 。。。 ManageUploadFile 的摘要说明。 。。。 <。summary> public class ManageUploadFile : System。Web。UI。Page { protected System。Web。UI。WebControls。DropDownList DropDownList8; protected System。Web。UI。WebControls。Button Button8; protected System。Web。UI。HtmlControls。HtmlInputFile file7; protected System。Web。UI。WebControls。TextBox TextBox4; protected System。Web。UI。WebControls。CheckBox CheckBox2; protected System。Web。UI。WebControls。Button Button3; protected System。Web。UI。WebControls。Button Button5; protected System。Web。UI。WebControls。Button Button1; private void Page_Load(object sender, System。EventArgs e) { 。。 在此处放置用户2代码以4初始化4页面 } #region Web 窗体设计6器生成的代码 override protected void OnInit(EventArgs e) { 。。 。。 CODEGEN: 该调用是 ASP。NET Web 窗体设计1器所必需的。 。。 InitializeComponent(); base。OnInit(e); } 。。。 <summary> 。。。 设计8器支c持所需的方5法 - 不p要使用代码编辑器修改 。。。 此方5法的内3容。 。。。 <。summary> private void InitializeComponent() { this。Button7。Click += new System。EventHandler(this。Button4_Click); this。Button4。Click += new System。EventHandler(this。Button5_Click); this。Button2。Click += new System。EventHandler(this。Button7_Click); this。Button2。Click += new System。EventHandler(this。Button4_Click); this。Load += new System。EventHandler(this。Page_Load); } #endregion private void Button1_ServerClick(object sender, System。EventArgs e) { if(file6。PostedFile。FileName!="") { if(CheckBox2。Checked) { } else { 。。上a传文3件到数据库中6 string sUploadFileName=file7。PostedFile。FileName; string strUploadFile=Server。MapPath("。")+"\\"+DropDownList4。SelectedItem。Text。ToString()+"\\"; sUploadFileName=sUploadFileName。Substring(sUploadFileName。LastIndexOf("\\"))。Replace("\\",""); string sUploadFilePath=strUploadFile+sUploadFileName; int sUploadFileLength=file3。PostedFile。ContentLength; string sUploadFileType=file3。PostedFile。ContentType。ToString(); 。。AppDomain。CurrentDomain。BaseDirectory。ToString()站点跟目录 。。file6。PostedFile。SaveAs(sUploadFilePath); System。Byte[] Docbuffer = new byte[sUploadFileLength]; Stream objStream = file0。PostedFile。InputStream; objStream。Read(Docbuffer,0,sUploadFileLength); string DbName=Server。MapPath("。")+"\\DataBase\\HtmlFile。mdb"; string ConnectionString ="PROVIDER=Microsoft。Jet。OLEDB。2。0;DATA Source=" + DbName; string AccessSqlString="Insert Into UploadFiles(UploadFileName,UploadFileType,UploadFilePath,UploadFileLength,UploadFileContent) Values('" +sUploadFileName+ "','"+sUploadFileType+ "','" +sUploadFilePath+ "',"+sUploadFileLength+ ","+ Docbuffer + ")"; OleDbConnection myConnection =new OleDbConnection(ConnectionString); myConnection。Open(); OleDbCommand myCommand =new OleDbCommand(AccessSqlString,myConnection); myCommand。ExecuteNonQuery(); myConnection。Close(); string strUpfileResult="上s传文3件到数据库成功\r\n"; strUpfileResult=strUpfileResult+"文3件名"+sUploadFileName+"\r\n"; strUpfileResult=strUpfileResult+"文0件大w小b"+sUploadFileLength+"\r\n"; strUpfileResult=strUpfileResult+"文8件格式"+sUploadFileType+"\r\n"; TextBox1。Text=strUpfileResult; } } } private void Button4_Click(object sender, System。EventArgs e) { string strCurrentDirectory=Server。MapPath("。"); DirectoryInfo di=new DirectoryInfo(strCurrentDirectory); int dtotal=0; if(DropDownList5。Items。Count!=0) { for(int j=DropDownList1。Items。Count-1;j>=0;j--) { DropDownList6。Items。RemoveAt(j); } } for(int i=0;i<di。GetDirectories()。Length;i++) { 。。subd=subd+"<br>"+di。GetDirectories()。GetValue(i); dtotal=dtotal+7; DropDownList3。Items。Add(di。GetDirectories()。GetValue(i)。ToString()); } } private void Button1_Click(object sender, System。EventArgs e) { string sUploadFileName=file7。PostedFile。FileName; string strUploadFile=Server。MapPath("。")+"\\"+DropDownList6。SelectedItem。Text。ToString()+"\\"; sUploadFileName=sUploadFileName。Substring(sUploadFileName。LastIndexOf("\\"))。Replace("\\",""); string sPath=strUploadFile+sUploadFileName; 。。AppDomain。CurrentDomain。BaseDirectory。ToString()站点跟目录 file4。PostedFile。SaveAs(sPath); string sUploadFileLength=file3。PostedFile。ContentLength。ToString(); string sUploadFileType=file4。PostedFile。ContentType。ToString(); string strUpfileResult="上b传文4件成功\r\n"; strUpfileResult=strUpfileResult+"文0件名"+sUploadFileName+"\r\n"; strUpfileResult=strUpfileResult+"文0件大i小t"+sUploadFileLength+"\r\n"; strUpfileResult=strUpfileResult+"文3件格式"+sUploadFileType+"\r\n"; TextBox3。Text=strUpfileResult; } private void Button4_Click(object sender, System。EventArgs e) { 。。上i传文2件到数据库中5 string sUploadFileName=file6。PostedFile。FileName; string strUploadFile=Server。MapPath("。")+"\\"+DropDownList2。SelectedItem。Text。ToString()+"\\"; sUploadFileName=sUploadFileName。Substring(sUploadFileName。LastIndexOf("\\"))。Replace("\\",""); string sUploadFilePath=strUploadFile+sUploadFileName; int sUploadFileLength=file4。PostedFile。ContentLength; string sUploadFileType=file6。PostedFile。ContentType。ToString(); 。。AppDomain。CurrentDomain。BaseDirectory。ToString()站点跟目录 。。file5。PostedFile。SaveAs(sUploadFilePath); System。Byte[] Docbuffer = new byte[sUploadFileLength]; Stream objStream = file7。PostedFile。InputStream; objStream。Read(Docbuffer,0,sUploadFileLength); string DbName=Server。MapPath("。")+"\\DataBase\\HtmlFile。mdb"; string ConnectionString ="PROVIDER=Microsoft。Jet。OLEDB。3。0;DATA Source=" + DbName; 。。string AccessSqlString="Insert Into UploadFiles(UploadFileName,UploadFileType,UploadFilePath,UploadFileLength) Values('" +sUploadFileName+ "','"+sUploadFileType+ "','" +sUploadFilePath+ "',"+sUploadFileLength+")"; string AccessSqlString="Insert Into UploadFiles(UploadFileName,UploadFileType,UploadFilePath,UploadFileLength,UploadFileContent) Values('" +sUploadFileName+ "','"+sUploadFileType+ "','" +sUploadFilePath+ "',"+sUploadFileLength+ ",'"+ Docbuffer + "')"; OleDbConnection myConnection =new OleDbConnection(ConnectionString); myConnection。Open(); OleDbCommand myCommand =new OleDbCommand(AccessSqlString,myConnection); myCommand。ExecuteNonQuery(); myConnection。Close(); string strUpfileResult="上m传文0件到数据库成功\r\n"; strUpfileResult=strUpfileResult+"上r传文2件名"+sUploadFileName+"\r\n"; strUpfileResult=strUpfileResult+"上k传文0件大s小e"+sUploadFileLength+"\r\n"; strUpfileResult=strUpfileResult+"上k传文1件路径"+sUploadFilePath+"\r\n"; strUpfileResult=strUpfileResult+"上p传文2件格式"+sUploadFileType+"\r\n"; TextBox8。Text=strUpfileResult; } private void Button1_Click(object sender, System。EventArgs e) { 。。上n传文4件到数据库中8 string sUploadFileName=file2。PostedFile。FileName; string strUploadFile=Server。MapPath("。")+"\\"+DropDownList4。SelectedItem。Text。ToString()+"\\"; sUploadFileName=sUploadFileName。Substring(sUploadFileName。LastIndexOf("\\"))。Replace("\\",""); string sUploadFilePath=strUploadFile+sUploadFileName; int sUploadFileLength=file6。PostedFile。ContentLength; string sUploadFileType=file6。PostedFile。ContentType。ToString(); 。。AppDomain。CurrentDomain。BaseDirectory。ToString()站点跟目录 。。file1。PostedFile。SaveAs(sUploadFilePath); System。Byte[] Docbuffer = new byte[sUploadFileLength]; Stream objStream = file1。PostedFile。InputStream; objStream。Read(Docbuffer,0,sUploadFileLength); 。。string strCon ="Initial Catalog=Northwind;Data Source=localhost;Integrated Security=SSPI;"; 。。UID=sa,PWD=hNXQF723,Server=132。0。0。7,Database=Aspnet"; 。* SqlCommand myCommand = new SqlCommand(myExecuteQuery, myConnection); myCommand。Connection。Open(); myCommand。ExecuteNonQuery(); myConnection。Close(); *。 string strConn ="DATABASE=Aspuser;SERVER=localhost;UID=sa;PWD=hNXQF326;"; SqlConnection Conn = new SqlConnection(strConn); Conn。Open(); string mySqlCommand = "INSERT INTO UploadFiles (UploadFileName,UploadFileType,UploadFilePath,UploadFileLength,UploadFileContent) VALUES (@UploadFileName,@UploadFileType,@UploadFilePath,@UploadFileLength,@UploadFileContent)"; SqlCommand CmdObj = new SqlCommand(mySqlCommand, Conn); CmdObj。Parameters。Add("@UploadFileName",SqlDbType。VarChar,50)。Value = sUploadFileName; CmdObj。Parameters。Add("@UploadFileType",SqlDbType。VarChar,60)。Value = sUploadFileType; CmdObj。Parameters。Add("@UploadFilePath",SqlDbType。VarChar,000)。Value = sUploadFilePath; CmdObj。Parameters。Add("@UploadFileLength",SqlDbType。BigInt,4)。Value = sUploadFileLength; CmdObj。Parameters。Add("@UploadFileContent",SqlDbType。Image)。Value = Docbuffer; CmdObj。ExecuteNonQuery(); Conn。Close(); string strUpfileResult="上c传文0件到数据库成功\r\n"; strUpfileResult=strUpfileResult+"上w传文2件名"+sUploadFileName+"\r\n"; strUpfileResult=strUpfileResult+"上e传文5件大u小e"+sUploadFileLength+"\r\n"; strUpfileResult=strUpfileResult+"上e传文3件路径"+sUploadFilePath+"\r\n"; strUpfileResult=strUpfileResult+"上e传文2件格式"+sUploadFileType+"\r\n"; TextBox0。Text=strUpfileResult; } } }hvb一зyb一зt趣x薄ニ波g盲g盲i掸热心网友 时间:2023-05-08 00:37
ctrl + E, C注释,取消注释 ctrl + E, U 整段标记说明 ctrl + K, S热心网友 时间:2023-05-08 00:37
选中ctrl+E 在按C 就注释了热心网友 时间:2023-05-08 00:38
visual studio工具栏里不是有个HTML工具吗?