.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Fetching File Information from selected foder

Posted By:shiv chandra       Posted Date: June 08, 2011    Points: 200    Category: C#    URL: http://www.dotnetspark.com  

This application will help you to learn to fetch basic information from files.

Many times it is required to list all the files from directory. Fetching file information like File Name, File Size, Extension.

By make use of DirectoryInfo class we can easily fetch information of file. Attached demo will show the use of DirectoryInfo class.Using just single loop you can achieve this task.

This application also provide facility of listing file from Root Folder as well as from all sub folders, for that you need to select radio button provided on top left corner.

Just browse the folder for which you need to list files, result will be updated in grid view.

if (fbdPath.ShowDialog() == DialogResult.OK)
    txtFolderPath.Text = fbdPath.SelectedPath;
    System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(fbdPath.SelectedPath);

    dgvFiles.Columns.Add("FileName", "File Name");
    dgvFiles.Columns.Add("Size", "File Size");
    dgvFiles.Columns.Add("Extension", "Extension");
    foreach (System.IO.FileInfo f in dir.GetFiles("*.*", rbtAllFolder.Checked ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
        dgvFiles.Rows.Add(f.Name, f.Length, f.Extension);

Here fbdPath is DialogBox for folder browser, txtFolderPath is path of selected folder, dgvFiles is DataGridView.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend