We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,078 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

view all files in a directory in grid style

Hi i need to view all files with their names and icons From a specific directory in a grid style inside my c# winform app

Any help would be appreciated
Thank you for your time

2
Contributors
3
Replies
4 Hours
Discussion Span
1 Year Ago
Last Updated
4
Views
Question
Answered
shandoosheri
Light Poster
42 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Let's say you have a directory c:\science with some .txt files in it.

You can put a DataGridView on your form and fill it like this:

using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;

namespace DW_404491_CS_FORM
{
   public partial class Form1 : Form
   {
      public Form1()
      {
         InitializeComponent();
      }

      private void Form1_Load(object sender, EventArgs e)
      {
         dataGridView1.DataSource =
         (
            from dir in Directory.GetFiles("c:/science/", "*.txt")
            select new
            {
               FileName = Path.GetFileName(dir.ToString())
            }
         ).ToList();
      }
   }
}
thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7

Thank you it helped me alot but does this also work with shortcuts instead of real files

shandoosheri
Light Poster
42 posts since Sep 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I did not test it with .lnk files.
All I can say is put some links in the target directory and test it.

thines01
Postaholic
Team Colleague
2,433 posts since Oct 2009
Reputation Points: 447
Solved Threads: 408
Skill Endorsements: 7
Question Answered as of 1 Year Ago by thines01

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0779 seconds using 2.65MB