6
Answers

GridView and Folder

Photo of M CH

M CH

9y
362
1
Dear Sir,
                I want to show data in the gridview from my folder. For example, I have a folder in my project and some pdf/word files about 60 or70. I want to show these files in the gridview  as select * from table where id . I shell be very thankful to you for this kindness. Thanks a lot.

Answers (6)

1
Photo of Amit Singh
NA 3.7k 46.7k 9y
 List<string> allFiles = new List<string
allFiles.AddRange(Directory.GetFiles(@"C:\test1\*"));
allFiles
.AddRange(Directory.GetFiles(@"C:\test2\*"));
yourGV
.DataSource = allFiles;
yourGV
.DataBind();
1
Photo of Vipan Sharma
NA 1.1k 935 9y
Try this.
 
string[] filePaths = Directory.GetFiles(Server.MapPath("~/Uploads/"));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
}
GridView1.DataSource = files;
GridView1.DataBind();
 
 
 
Modify if you need filter result
1
Photo of Amit Singh
NA 3.7k 46.7k 9y
hey,
 
http://www.aspdotnet-suresh.com/2013/08/c-get-all-files-from-folder-and.html
 
http://www.c-sharpcorner.com/blogs/display-images-in-gridview-from-folder-in-asp-net1
0
Photo of Vipan Sharma
NA 1.1k 935 9y
You Welcome,  Happy Coding !!!!!
Accept Right answer. So it will help next person.
 
 
 
0
Photo of M CH
NA 183 12.8k 9y
Thanks for help
0
Photo of Shubham Kumar
NA 6.5k 260.7k 9y
Hi,
R u saving the name or path of the document in the db 
just visit the link it may help you 
 
http://www.aspsnippets.com/Articles/Display-list-of-files-from-Server-folder-in-ASPNet-GridView.aspx 
 
http://www.aspdotnet-suresh.com/2014/07/aspnet-display-list-of-files-from-server-folder-in-gridview.html