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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s