asp.net 遍曆檔案夾下全部子檔案夾並綁定到gridview上

來源:互聯網
上載者:User

標籤:http   io   檔案   for   ar   art   div   代碼   

遍曆檔案夾下所有子檔案夾,並且遍曆設定檔某一節點中所有key,value並且綁定到GridView上 

C#代碼  
    1. Helper app_Helper = new Helper();  
    2.   
    3. DataSet ds = new DataSet();  
    4.   
    5. DataTable dt = new DataTable();  
    6.       
    7. protected void Page_Load(object sender, EventArgs e)  
    8. {  
    9.     gvwBind();  
    10. }  
    11.  
    12. #region 綁定GridView  
    13.   
    14. /// <summary>  
    15. /// 綁定GridView  
    16. /// </summary>  
    17. protected void gvwBind()  
    18. {  
    19.     INI.INIPath iniINIPath = new INI.INIPath();  
    20.         INI.INIFile iniINIFile = new INI.INIFile(iniINIPath.getINIPath());  
    21.   
    22.     string FolderNames = app_Helper.GetAllFolder(Server.MapPath("../../APPDIR"));//獲得APPDIR檔案夾下所有子檔案夾名  
    23.   
    24.     string[] FolderName = new string[FolderNames.Split(‘,‘).Length - 1];//聲明個數組為了儲存檔案夾絕對路徑  
    25.   
    26.     FolderName = FolderNames.Split(‘,‘);//給檔案夾絕對路徑數組賦值  
    27.   
    28.     dt.Columns.Add("LKNAME", typeof(string));  
    29.     dt.Columns.Add("qdjsjm", typeof(string));  
    30.     dt.Columns.Add("qdipdz", typeof(string));  
    31.   
    32.     for (int i = 0; i < FolderName.Length - 1; i++)  
    33.     {  
    34.         DataRow row = dt.NewRow();  
    35.   
    36.         FolderName[i] = FolderName[i].Substring(FolderName[i].LastIndexOf(‘\\‘) + 1);//截取檔案夾名  
    37.   
    38.         row["LKNAME"] = FolderName[i];//給 LKNAME 字元賦值  
    39.   
    40.         if (!iniINIFile.IniReadValue("dzjclkzp", FolderName[i]).Equals(""))//設定檔中是否存在相同檔案夾名的key  
    41.         {  
    42.             row["qdjsjm"] = iniINIFile.IniReadValue("dzjclkzp", FolderName[i]).Split(‘,‘)[0];//給qdjsjm欄位賦值  
    43.             row["qdipdz"] = iniINIFile.IniReadValue("dzjclkzp", FolderName[i]).Split(‘,‘)[1];//給qdipdz欄位賦值  
    44.         }  
    45.   
    46.         dt.Rows.Add(row);  
    47.     }  
    48.   
    49.     gvwGKWH.DataSource = dt;//綁定到數組  
    50.     gvwGKWH.DataBind();  
    51. }  
    52.  
    53. #endregion 綁定GridView  

推薦篇文章

  • 我來說說我所理解的團隊精神

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.