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.
Some of my
previous articles are as follows: Short
GridView Data From Header Using C#.Net In Asp.Net, Export
GridView Or Table Data Into PDF By C#.Net In Asp.Net Using jQuery, Enable
and Disable ADO.NET and OLEDB Connection Pooling In .Net, Group
CheckBox In C# WinForm, Read
Outlook Email Subject Using c#, Read
Outlook Inbox Mail And Email Count Of Inbox Using C#.Net, How
To Read XML File In DataSet And Display in DataGridview Using C#.Net.
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.
0 comments:
Please let me know your view