none
How to load configuration file in the specific path and name RRS feed

  • Question

  • I need to load configuration file in the specific path and name.

    How could I do this?

    (for example, C:\Program Files (x86)\MyApp\Cfg\test.cfg)

    Tuesday, March 26, 2019 3:22 AM

Answers

  • Is there any rule to set the configuration file?

    I use following name and location.

         <Application path>\Cfg\test.cfg

    The rules are your's until it fails so there are no true rules for desktop apps.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Jeff0803 Wednesday, March 27, 2019 4:55 PM
    Wednesday, March 27, 2019 2:46 PM
    Moderator

All replies

  • What kind of a config file, becuase it looks like something you mad up that may not look to be an config file format like an app.config oy myprogram.exe.config?
    Tuesday, March 26, 2019 4:45 AM
  • My config file is like app.config but use different name and folder for some reason.
    Tuesday, March 26, 2019 2:07 PM
  • Hello,

    Look at ExeConfigurationFileMap.

    Example below from this post.

    ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
    configMap.ExeConfigFilename = @"d:\test\justAConfigFile.config.whateverYouLikeExtension";
    Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None);


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, March 26, 2019 2:34 PM
    Moderator
  • My config file is like app.config but use different name and folder for some reason.

    So why can't you use myprogram.exe.config, the runtime config file that sits at the same location that myprogram.exe sits? You can us ConfigurationManager to read the myprogram.exe.config file.

    https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/

    Tuesday, March 26, 2019 7:37 PM
  • In some case, we should load configuration file with specific name(for example test.cfg) from some specific folder.

    Is there any limit to load configuration file?

    If I see the MSDN, ConfigurationManager.OpenMappedExeConfiguration() seems to do this but practically doesn't work in my case.

    Wednesday, March 27, 2019 2:31 PM
  • Is there any rule to set the configuration file?

    I use following name and location.

         <Application path>\Cfg\test.cfg

    Wednesday, March 27, 2019 2:33 PM
  • Is there any rule to set the configuration file?

    I use following name and location.

         <Application path>\Cfg\test.cfg

    The rules are your's until it fails so there are no true rules for desktop apps.

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by Jeff0803 Wednesday, March 27, 2019 4:55 PM
    Wednesday, March 27, 2019 2:46 PM
    Moderator
  • How could I save as <application path>\myprog.exe.config?

    I posted here and described my problem in detail.


    • Edited by Jeff0803 Thursday, March 28, 2019 5:52 PM
    Thursday, March 28, 2019 5:49 PM