新聞中心
這里有您想知道的互聯(lián)網營銷解決方案
C#文件上傳下載及列表相關代碼示例
C#文件上傳下載是對文件的基本操作,C#文件上傳下載主要實現的是對文件的管理與應用。這里介紹的代碼將實現大部分功能。

為寒亭等地區(qū)用戶提供了全套網頁設計制作服務,及寒亭網站建設行業(yè)解決方案。主營業(yè)務為成都做網站、成都網站建設、寒亭網站設計,以傳統(tǒng)方式定制建設網站,并提供域名空間備案等一條龍服務,秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務。我們深信只要達到每一位用戶的要求,就會得到認可,從而選擇與我們長期合作。這樣,我們也可以走得更遠!
1.文件上傳
如下要點:
HTML部分:
- id=\"form1\" runat=\"server\" method=\"post\" enctype=\"multipart/form-data\">
- id=\"FileUpLoad\" type=\"file\" runat=\"server\"/>
/>- 后臺CS部分 按鈕事件
- //string strFileFullName = System.IO.Path.GetFileName(this.FileUpLoad.PostedFile.FileName);
- //this.FileUpLoad.PostedFile.SaveAs(Server.MapPath(\"./Xmlzip/\") + strFileFullName);
2.文件下載
ListBox的SelectedIndexChanged事件 設定相關下載連接
- 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值 來實現點擊后實現文件下載的超級連接
this.Label1.Text = \"a.rar\"
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 得到當前可用的文件列表
- ///
- /// 得到當前可用的文件列表
- ///
- /// 是否需要彈出提示信息
- private void fn_getCurrFileList(bool IsAlert)
- {
- try
- {
- //查找Xmlzip文件夾下 屬于其本身UnitCoding的相關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#文件上傳下載及列表相關代碼示例就介紹到這里。
文章題目:C#文件上傳下載及列表相關代碼示例
當前地址:http://m.fisionsoft.com.cn/article/copeiii.html


咨詢
建站咨詢
