Paul Robinson
Paul Robinson

Reputation: 41

VB.Net How to move the app.config file to a custom location

I have an application that has a load of values in its app.exe.config file. The application is used by a few users, and the settings would change on a regular basis. so im having to change the config file, and send it out to all users.

I'd love to move the config file to the network somewhere and point the app to this file. ive tried to use;

Imports System.Configuration.ConfigurationManager

OpenExeConfiguration("I:\app config\HelpDeskQuickCallLogger.exe.config")

But i cant get it to read in the values.

Anyone any ideas?

Upvotes: 4

Views: 2970

Answers (2)

competent_tech
competent_tech

Reputation: 44931

This is how we handle this requirement if a specific configuration file (sSpecificConfigurationFile) is specified:

    Dim oConfig As System.Configuration.Configuration

    If sSpecificConfigurationFile.EndsWith(".config", StringComparison.InvariantCultureIgnoreCase) Then
        Dim oMap As New ExeConfigurationFileMap
        oMap.ExeConfigFilename = sSpecificConfigurationFile
        oConfig = ConfigurationManager.OpenMappedExeConfiguration(oMap, ConfigurationUserLevel.None)
    Else
        oConfig = ConfigurationManager.OpenExeConfiguration(sSpecificConfigurationFile)
    End If

Upvotes: 1

Mark Hall
Mark Hall

Reputation: 54532

I am not sure if this is what you are looking for but see if this Code Project Article helps.

Description from above article:

This article demonstrates how to write a custom Settings Provider to allow you to persist your My.Settings to your own storage system.

Upvotes: 1

Related Questions