這篇文章主要講解了“如何利用C#操作文件和列表”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“如何利用C#操作文件和列表”吧!
阿勒泰ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!
C#文件上傳下載是對文件的基本操作,C#文件上傳下載主要實現(xiàn)的是對文件的管理與應(yīng)用。這里介紹的代碼將實現(xiàn)大部分功能。
1.文件上傳
如下要點:
HTML部分:
<form id=\"form1\" runat=\"server\" method=\"post\" enctype=\"multipart/form-data\"> <input id=\"FileUpLoad\" type=\"file\" runat=\"server\"/><br /> 后臺CS部分 按鈕事件 //string strFileFullName = System.IO.Path.GetFileName(this.FileUpLoad.PostedFile.FileName); //this.FileUpLoad.PostedFile.SaveAs(Server.MapPath(\"./Xmlzip/\") + strFileFullName);
2.文件下載
ListBox的SelectedIndexChanged事件 設(shè)定相關(guān)下載連接
protected void lst_DownLoadFileList_SelectedIndexChanged(object sender, EventArgs e) { try { string strJS = \"window.open(\'Xmlzip/\"; strJS += this.lst_DownLoadFileList.SelectedItem.Text.Trim(); strJS += \"\'); return false; \"; this.imgbtn_DownLoadFile.Attributes.Add(\"onclick\", strJS); } catch (Exception ex) { ex.ToString(); } }
或者也可以通過 改變Label的Text值 來實現(xiàn)點擊后實現(xiàn)文件下載的超級連接
this.Label1.Text = \"<a href=\\\"Xmlzip/a.rar\\\">a.rar</a>\"
3.文件刪除
string strFilePath = 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\"); } }
4.得到文件夾下的文件列表
#region 得到當(dāng)前可用的文件列表 /// <summary> /// 得到當(dāng)前可用的文件列表 /// </summary> /// <param name=\"IsAlert\">是否需要彈出提示信息</param> private void fn_getCurrFileList(bool IsAlert) { try { //查找Xmlzip文件夾下 屬于其本身UnitCoding的相關(guān)zip文件 string strXmlZipDirectory = Server.MapPath(\"../Xmlzip/\"); if (Directory.Exists(strXmlZipDirectory)) { //DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory); DirectoryInfo di = new DirectoryInfo(strXmlZipDirectory); FileInfo[] FI = di.GetFiles(\"*.zip\");//只查.zip文件 if (FI.Length > 0) { lst_DownLoadFileList.Items.Clear(); foreach (FileInfo tmpFI in FI) { ListItem tmpItem = new ListItem(); tmpItem.Text = tmpFI.Name; lst_DownLoadFileList.Items.Add(tmpItem); } lst_DownLoadFileList.SelectedIndex = 0; } else { if (IsAlert) { Response.write(\"查無可以下載的文件!\"); } } } } catch (Exception ex) { ex.ToString(); } } #endregion
感謝各位的閱讀,以上就是“如何利用C#操作文件和列表”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對如何利用C#操作文件和列表這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!
網(wǎng)頁題目:如何利用C#操作文件和列表
文章源于:http://www.chinadenli.net/article18/pegggp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、營銷型網(wǎng)站建設(shè)、微信小程序、網(wǎng)站策劃、微信公眾號、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)