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
- Helper app_Helper = new Helper ();
- DataSet ds = new DataSet ();
- DataTable dt = new DataTable ();
- Protected void Page_Load (object sender, EventArgs e)
- {
- GvwBind ();
- }
-
- # Region bind the GridView
- /// <Summary>
- /// Bind the GridView
- /// </Summary>
- Protected void gvwBind ()
- {
- INI. INIPath iniINIPath = new INI. INIPath ();
- INI. INIFile iniINIFile = new INI. INIFile (iniINIPath. getINIPath ());
- String FolderNames = app_Helper.GetAllFolder (Server. MapPath (".../../APPDIR"); // obtain the names of all subfolders in the appdir folder
- String [] FolderName = new string [FolderNames. Split (','). Length-1]; // declare an array to save the absolute path of the folder
- FolderName = FolderNames. Split (','); // assign a value to the absolute path array of the folder.
- Dt. Columns. Add ("LKNAME", typeof (string ));
- Dt. Columns. Add ("qdjsjm", typeof (string ));
- Dt. Columns. Add ("qdipdz", typeof (string ));
- For (int I = 0; I <FolderName. Length-1; I ++)
- {
- DataRow row = dt. NewRow ();
- FolderName [I] = FolderName [I]. Substring (FolderName [I]. LastIndexOf ('\') + 1); // capture the folder name
- Row ["LKNAME"] = FolderName [I]; // assign a value to the LKNAME character
- If (! IniINIFile. IniReadValue ("dzjclkzp", FolderName [I]). Equals ("") // check whether the key with the same folder name exists in the configuration file
- {
- Row ["qdjsjm"] = iniINIFile. IniReadValue ("dzjclkzp", FolderName [I]). Split (',') [0]; // assign a value to the qdjsjm Field
- Row ["qdipdz"] = iniINIFile. IniReadValue ("dzjclkzp", FolderName [I]). Split (',') [1]; // assign a value to the qdipdz Field
- }
- Dt. Rows. Add (row );
- }
- GvwGKWH. DataSource = dt; // bind to an array
- GvwGKWH. DataBind ();
- }
-
- # 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.