日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
C#文件上傳下載及列表相關(guān)代碼示例

C#文件上傳下載是對文件的基本操作,C#文件上傳下載主要實(shí)現(xiàn)的是對文件的管理與應(yīng)用。這里介紹的代碼將實(shí)現(xiàn)大部分功能。

為寒亭等地區(qū)用戶提供了全套網(wǎng)頁設(shè)計(jì)制作服務(wù),及寒亭網(wǎng)站建設(shè)行業(yè)解決方案。主營業(yè)務(wù)為成都做網(wǎng)站、成都網(wǎng)站建設(shè)、寒亭網(wǎng)站設(shè)計(jì),以傳統(tǒng)方式定制建設(shè)網(wǎng)站,并提供域名空間備案等一條龍服務(wù),秉承以專業(yè)、用心的態(tài)度為用戶提供真誠的服務(wù)。我們深信只要達(dá)到每一位用戶的要求,就會得到認(rèn)可,從而選擇與我們長期合作。這樣,我們也可以走得更遠(yuǎn)!

1.文件上傳

如下要點(diǎn):

HTML部分:

 
 
 
  1.  id=\"form1\" runat=\"server\" method=\"post\" enctype=\"multipart/form-data\"> 
  2.      id=\"FileUpLoad\" type=\"file\" runat=\"server\"/> /> 
  3.     后臺CS部分 按鈕事件  
  4.     //string strFileFullName = System.IO.Path.GetFileName(this.FileUpLoad.PostedFile.FileName);  
  5.     //this.FileUpLoad.PostedFile.SaveAs(Server.MapPath(\"./Xmlzip/\") + strFileFullName); 

2.文件下載

ListBox的SelectedIndexChanged事件 設(shè)定相關(guān)下載連接    

 
 
 
  1. protected void lst_DownLoadFileList_SelectedIndexChanged(object sender, EventArgs e)  
  2.         {  
  3.             try 
  4.             {  
  5.                 string strJS = \"window.open(\'Xmlzip/\";  
  6.                 strJS += this.lst_DownLoadFileList.SelectedItem.Text.Trim();  
  7.                 strJS += \"\'); return false; \";  
  8.                 this.imgbtn_DownLoadFile.Attributes.Add(\"onclick\", strJS);  
  9.             }  
  10.             catch (Exception ex)  
  11.             {  
  12.                 ex.ToString();  
  13.             }  
  14.         } 

或者也可以通過 改變Label的Text值 來實(shí)現(xiàn)點(diǎn)擊后實(shí)現(xiàn)文件下載的超級連接

this.Label1.Text = \"a.rar\"

3.文件刪除

 
 
 
  1. string strFilePath = Server.MapPath(\"../CountryFlowMgr/Xmlzip/\"+this.lst_DownLoadFileList.SelectedItem.Text.Trim());  
  2.     if (File.Exists(strFilePath))  
  3.     {  
  4.        File.Delete(strFilePath);  
  5.        if (File.Exists(strFilePath))  
  6.        {  
  7.      Response.Write(\"ok\");  
  8.        }  
  9.        else 
  10.        {  
  11.             Response.Write(\"ok\");  
  12.        }  
  13.     } 

4.得到文件夾下的文件列表

 
 
 
  1. #region 得到當(dāng)前可用的文件列表  
  2.         ///   
  3.         /// 得到當(dāng)前可用的文件列表  
  4.         ///   
  5.         /// 是否需要彈出提示信息  
  6.         private void fn_getCurrFileList(bool IsAlert)  
  7.         {  
  8.             try 
  9.             {  
  10.                 //查找Xmlzip文件夾下 屬于其本身UnitCoding的相關(guān)zip文件  
  11.                 string strXmlZipDirectory = Server.MapPath(\"../Xmlzip/\");  
  12.                 if (Directory.Exists(strXmlZipDirectory))  
  13.                 {  
  14.                     //DirectoryInfo di = new DirectoryInfo(Environment.CurrentDirectory);  
  15.                     DirectoryInfo di = new DirectoryInfo(strXmlZipDirectory);  
  16.  
  17.                     FileInfo[] FI = di.GetFiles(\"*.zip\");//只查.zip文件  
  18.                     if (FI.Length > 0)  
  19.                     {  
  20.                         lst_DownLoadFileList.Items.Clear();  
  21.                         foreach (FileInfo tmpFI in FI)  
  22.                         {  
  23.                             ListItem tmpItem = new ListItem();  
  24.                             tmpItem.Text = tmpFI.Name;  
  25.                             lst_DownLoadFileList.Items.Add(tmpItem);  
  26.                         }  
  27.                         lst_DownLoadFileList.SelectedIndex = 0;  
  28.         }  
  29.                     else 
  30.                     {  
  31.                         if (IsAlert)  
  32.                         {  
  33.                             Response.write(\"查無可以下載的文件!\");  
  34.                         }  
  35.                     }  
  36.                 }  
  37.             }  
  38.             catch (Exception ex)  
  39.             {  
  40.                 ex.ToString();  
  41.             }  
  42.         }  
  43.         #endregion 

C#文件上傳下載及列表相關(guān)代碼示例就介紹到這里。


本文標(biāo)題:C#文件上傳下載及列表相關(guān)代碼示例
URL分享:http://www.dlmjj.cn/article/copeiii.html