Tuesday, 3 May 2016

Retrieve All Files Present inside a Directory & Sub Directory Using C#.Net

5/03/2016 - By Pranav Singh 0

This article will show you how you can retrieve all the files present inside the parent directory and inside the sub directory using c#.Net in a list collection.
So for this article first we will create a new console application and add the below code into the main function.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> fileCollection = new List<string>();
            string directoryPath = @"-----------------";
            fileCollection = Directory.GetFiles(directoryPath, "*", SearchOption.AllDirectories).ToList();
            Console.WriteLine("------File Read Start--------\n");
            foreach (string item in fileCollection)
            {
                Console.WriteLine(item + ", ");
            }
            Console.WriteLine("------File Read End--------\n");
            Console.ReadLine();
        }
    }
}



In above code I have specified he path of the folder to read all the files. Now we have done run the application to check the output.



Tags: ,
About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top