Tag Archives: Reflection

Retrieving files from application directory using Reflection

When retrieving a list of files in the directory of the executing application/DLL you can use the following code:

 Dim uri As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) Dim local As String = New Uri(uri).LocalPath
 Dim filenames() As String = System.IO.Directory.GetFiles(local, “*.*”)

CodeBase returns a URI which means that if you pass the result of GetDirectoryName directly to GetFiles a ‘URI formats are not supported’ error is thrown. Thus we need to convert the URI to a local path.