Click here to Skip to main content
15,941,071 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
How to display a file which is located in a folder or a subfolder using a GridView or any other control that contains delete option in an asp.net Web Page?
Posted
Comments
Sergey Alexandrovich Kryukov 11-Jun-12 0:10am    
What is the problem? How to use grid view? How to open and read the file? And you say nothing about the file you would read...
--SA

Use following to get list of files in a folder. Once you have it, display it in a control that has features you want - Grid, Treeview, Listview, etc.
Get Files from Directory [C#][^]

Try and post specific issue if you get stuck.
 
Share this answer
 
Use Directory class GetFiles function.
C#
string path=@"c:\";
string[] files = System.IO.Directory.GetFiles(path);

// ...

After that bind the files collection to Gridview.
 
Share this answer
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Files_Folder;
using System.IO;
using System.Data;
namespace WriteListFileFolder
{
    class Program
    {
        static void Main(string[] args)
        {
            DataTable DtTblList;
            DtTblList = new DataTable();
            DtTblList.Columns.Add("SrNo", typeof(int));
            DtTblList.Columns.Add("EntryType", typeof(int));
            DtTblList.Columns.Add("Path", typeof(string));

            GetFileFolders(ref DtTblList, "D:\\GSDIntegration");
            DtTblList.WriteXml("D\\XmlFile.xml");
        }
        static void GetFileFolders(ref DataTable DtTblList, string FolderPath)
        {
            string[] ListDirectory = Directory.GetDirectories( FolderPath);
            if (ListDirectory.Length > 0)
            {
                for (int n = 0; n < ListDirectory.Length; n++)
                {
                    DataRow _D = DtTblList.NewRow();
                    _D["SrNo"] = DtTblList.Rows.Count + 1; _D["EntryType"] = 1;
                    _D["Path"] = ListDirectory[n]; DtTblList.Rows.Add(_D);
                    GetFileFolders(ref DtTblList, ListDirectory[n]);
                }
            }
            else
            {
                string[] ListOfFiles = Directory.GetFiles(FolderPath);
                for (int i = 0; i < ListOfFiles.Length; i++)
                {
                    DataRow _D = DtTblList.NewRow();
                    _D["SrNo"] = DtTblList.Rows.Count + 1; _D["EntryType"] = 2;
                    _D["Path"] = ListOfFiles[i]; DtTblList.Rows.Add(_D);
                }
            }
        }
    }
}
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900