Asp.net traverses all subfolders in the folder and binds them to the gridview. asp. netgridview

Source: Internet
Author: User

Asp.net traverses all subfolders in the folder and binds them to the gridview. asp. netgridview

Traverse all subfolders in the folder, traverse all keys and values in a node of the configuration file, and bind them to the GridView.

C # code
    1. Helper app_Helper = new Helper ();
    2. DataSet ds = new DataSet ();
    3. DataTable dt = new DataTable ();
    4. Protected void Page_Load (object sender, EventArgs e)
    5. {
    6. GvwBind ();
    7. }
    8.  
    9. # Region bind the GridView
    10. /// <Summary>
    11. /// Bind the GridView
    12. /// </Summary>
    13. Protected void gvwBind ()
    14. {
    15. INI. INIPath iniINIPath = new INI. INIPath ();
    16. INI. INIFile iniINIFile = new INI. INIFile (iniINIPath. getINIPath ());
    17. String FolderNames = app_Helper.GetAllFolder (Server. MapPath (".../../APPDIR"); // obtain the names of all subfolders in the appdir folder
    18. String [] FolderName = new string [FolderNames. Split (','). Length-1]; // declare an array to save the absolute path of the folder
    19. FolderName = FolderNames. Split (','); // assign a value to the absolute path array of the folder.
    20. Dt. Columns. Add ("LKNAME", typeof (string ));
    21. Dt. Columns. Add ("qdjsjm", typeof (string ));
    22. Dt. Columns. Add ("qdipdz", typeof (string ));
    23. For (int I = 0; I <FolderName. Length-1; I ++)
    24. {
    25. DataRow row = dt. NewRow ();
    26. FolderName [I] = FolderName [I]. Substring (FolderName [I]. LastIndexOf ('\') + 1); // capture the folder name
    27. Row ["LKNAME"] = FolderName [I]; // assign a value to the LKNAME character
    28. If (! IniINIFile. IniReadValue ("dzjclkzp", FolderName [I]). Equals ("") // check whether the key with the same folder name exists in the configuration file
    29. {
    30. Row ["qdjsjm"] = iniINIFile. IniReadValue ("dzjclkzp", FolderName [I]). Split (',') [0]; // assign a value to the qdjsjm Field
    31. Row ["qdipdz"] = iniINIFile. IniReadValue ("dzjclkzp", FolderName [I]). Split (',') [1]; // assign a value to the qdipdz Field
    32. }
    33. Dt. Rows. Add (row );
    34. }
    35. GvwGKWH. DataSource = dt; // bind to an array
    36. GvwGKWH. DataBind ();
    37. }
    38.  
    39. # Bind endregion to the GridView

Recommended articles

  • Let me talk about the team spirit that I understand.

Hurry up, aspnet C # traverse the files in the folder and bind the file name to the GridView. How can I write the download path to download these files?

Just output the files on the server to the client as a stream.

Aspnet (c #) traverses a folder with TreeView. How can I click a node to open the file?

Now that you have traversed the folder
Add it cyclically in the selectedChanged event
System. Diagnostics. Process. Start ("f: \ a.txt ");
Next, just traverse it again and try again. Wish you success.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.