Luke Wyatt
Luke Wyatt

Reputation: 1136

.NET Replacement Shell not retrieving file contents during startup

I have an application I wrote that replaces Windows Explorer as a shell for Kiosk purposes. The application maintains two configuration files: one that is used and maintained for application purpose (app.config) and another that is stored in another directory so it doesn't get overwritten when the GUI attempts to update from a repository.

When the application is ran in a normal environment it works perfectly. However when it is used during start-up or when switching users, the application can't seem to load the information in the other directory.

From the manager class

Private Shared rootCP As String
Friend Shared Sub loadConfig()

    Dim dir As New IO.DirectoryInfo(Environment.CurrentDirectory)

    Try
        Dim objReader As New System.IO.StreamReader(dir.Parent.FullName & "\local.config")
        rootCP = objReader.ReadToEnd
        objReader.Close()
    Catch Ex As Exception
        'DEBUG: console.write(ex.message)
    End Try

    dir = Nothing

End Sub

From the MainForm_Load sub

Manager.loadConfig()

Another function later attempts to retrieve the data from the rootCP string but can only access it if the application was started after system start-up. Any thoughts (VB.NET or C# is fine)?

Upvotes: 0

Views: 163

Answers (1)

Andrew
Andrew

Reputation: 8673

One of these might work for you. I almost always use Assembly.GetEntryAssembly().Location. Don't use CodeBase on the assembly, it can be something you might not expect.

Assembly.GetEntryAssembly().Location
AppDomain.CurrentDomain.BaseDirectory

For windows apps:

Application.ExecutablePath

Because the normal ways aren't working, it's hard for me to say which of these will for sure. Also, always use Path.Combine(...) to pull two paths together.

Upvotes: 2

Related Questions