get files from application root path

The following code written in C# Language and use for gets all files from the application root path.

try
{
    string fileName = System.Reflection.Assembly.GetExecutingAssembly( ).Location;
    fileName = fileName.Substring( 0, fileName.LastIndexOf( ‘\\’ ) );
    string [] files = Directory.GetFiles( fileName );
    for( int i = 0; i < files.Length; i++ )
    {
        Console.WriteLine( Path.GetFileName( files [ i ] ) );
    }
}
catch( IOException )
{
    Console.WriteLine( “IOException” );
}
Console.ReadKey( );

And thanks to my friend “wasif” to help me for get application root path.
Regards,
-aims

Leave a comment