溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

C#文件列表操作有哪些重點(diǎn)

發(fā)布時(shí)間:2021-07-16 16:15:41 來源:億速云 閱讀:171 作者:chen 欄目:編程語言

本篇內(nèi)容主要講解“C#文件列表操作有哪些重點(diǎn)”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“C#文件列表操作有哪些重點(diǎn)”吧!

C#文件列表要點(diǎn)1:上傳文件

HTML部分:

〈 formid=\"form1\"runat=\" server\"method=\"post\"enctype=\  "multipart/form-data\"〉  〈 inputid=\"FileUpLoad\"type=\" file\"runat=\"server\"/〉〈 br/〉  后臺(tái)CS部分按鈕事件  //stringstrFileFullName=  System.IO.Path.GetFileName(this.  FileUpLoad.PostedFile.FileName);  //this.FileUpLoad.PostedFile.SaveAs(Server.MapPath(  \"./Xmlzip/\")+strFileFullName);

C#文件列表要點(diǎn)2.文件下載

ListBox的SelectedIndexChanged事件設(shè)  定相關(guān)下載連接  protectedvoidlst_DownLoadFileList  _SelectedIndexChanged(objectsender,EventArgse)  {  try  {  stringstrJS=\"window.open(\'Xmlzip/\";  strJS+=this.lst_DownLoadFileList.  SelectedItem.Text.Trim();  strJS+=\"\');returnfalse;\";  this.imgbtn_DownLoadFile.Attributes.  Add(\"onclick\",strJS);  }  catch(Exceptionex)  {  ex.ToString();  }  }  或者也可以通過改變Label的Text值來實(shí)現(xiàn)點(diǎn)擊  后實(shí)現(xiàn)文件下載的超級連接  this.Label1.Text=\"〈 ahref=  \\\"Xmlzip/a.rar\\\"〉a.rar〈 /a〉\"

C#文件列表要點(diǎn)3.文件刪除

stringstrFilePath=Server.MapPath(  \"../CountryFlowMgr/Xmlzip/\"+this.lst_  DownLoadFileList.SelectedItem.Text.Trim());  if(File.Exists(strFilePath))  {  File.Delete(strFilePath);  if(File.Exists(strFilePath))  {  Response.Write(\"ok\");  }  else {  Response.Write(\"ok\");  }  }

C#文件列表要點(diǎn)4.得到文件夾下的文件列表

#region得到當(dāng)前可用的文件列表  ///〈 summary〉  ///得到當(dāng)前可用的文件列表  ///〈 /summary〉  ///〈 paramname=\"IsAlert\"〉  是否需要彈出提示信息〈 /param〉  privatevoidfn_getCurrFileList(boolIsAlert)  {  try  {  //查找Xmlzip文件夾下屬于其本  身UnitCoding的相關(guān)zip文件  stringstrXmlZipDirectory=  Server.MapPath(\"../Xmlzip/\");  if(Directory.Exists(strXmlZipDirectory))  {  //DirectoryInfodi=newDirectoryInfo(  Environment.CurrentDirectory);  DirectoryInfodi=newDirectoryInfo(  strXmlZipDirectory);   FileInfo[]FI=di.GetFiles(\"*.zip\" );//只查.zip文件  if(FI.Length〉0)  {  lst_DownLoadFileList.Items.Clear();  foreach(FileInfotmpFIinFI)  {  ListItemtmpItem=newListItem();  tmpItem.Text=tmpFI.Name;  lst_DownLoadFileList.Items.Add(tmpItem);  }  lst_DownLoadFileList.SelectedIndex=0;  }  else {  if(IsAlert)  {  Response.write(\"查無可以下載的文件!\");  }  }  }  }  catch(Exceptionex)  {  ex.ToString();  }  }  #endregion

到此,相信大家對“C#文件列表操作有哪些重點(diǎn)”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI