none
How to load configuration file of which name is not related to the exe file name RRS feed

  • Question

  • It seems ConfigurationManager.OpenExeConfiguration() is related to the current application's name.

    I want to load the configuration file of which name is not related to the exe file name.

    For example, application file name is "MyApp.exe" and custom configuration file name is "OtherApp.exe.config".

    In following methods, Which method should I use to load OtherApp.exe.config from MyApp.exe?

    OpenExeConfiguration()
    OpenMachineConfiguration()
    OpenMappedExeConfiguration()
    OpenMappedMachineConfiguration()





    • Edited by Jeff0803 Thursday, January 10, 2019 8:58 PM
    Thursday, January 10, 2019 4:40 PM

Answers

  • OpenMappedExeConfiguration is the method you'd use. The Map portion of the names are for mapping to a custom name. ExeConfiguration is for executable configs (vs the machine config). If you look in the example in the documentation you'll see it first opens the regular config file. Then it renames it and opens the new file mapped. That is the logic you need to open an arbitrary config file.

    Michael Taylor http://www.michaeltaylorp3.net

    • Proposed as answer by Stanly Fan Monday, January 14, 2019 1:32 AM
    • Marked as answer by Jeff0803 Thursday, March 28, 2019 5:25 PM
    Friday, January 11, 2019 3:10 PM
    Moderator
  • Hi,

    Any update? Do you resolve the issue?

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Jeff0803 Thursday, March 28, 2019 5:25 PM
    Monday, February 4, 2019 7:07 AM
    Moderator

All replies

  • The configuration file is just a XML file.

    https://stackoverflow.com/questions/32758596/c-sharp-linq-to-xml-read-a-xml-config-file

    https://www.dotnetcurry.com/linq/564/linq-to-xml-tutorials-examples

    Friday, January 11, 2019 4:18 AM
  • OpenMappedExeConfiguration is the method you'd use. The Map portion of the names are for mapping to a custom name. ExeConfiguration is for executable configs (vs the machine config). If you look in the example in the documentation you'll see it first opens the regular config file. Then it renames it and opens the new file mapped. That is the logic you need to open an arbitrary config file.

    Michael Taylor http://www.michaeltaylorp3.net

    • Proposed as answer by Stanly Fan Monday, January 14, 2019 1:32 AM
    • Marked as answer by Jeff0803 Thursday, March 28, 2019 5:25 PM
    Friday, January 11, 2019 3:10 PM
    Moderator
  • Hi,

    Any update? Do you resolve the issue?

    Best regards,

    Zhanglong


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Jeff0803 Thursday, March 28, 2019 5:25 PM
    Monday, February 4, 2019 7:07 AM
    Moderator
  • Still I'm suffering with this issue.

    I posted with new title named "How to load configuration file from specific folder and save it to application path with different file name?".

    Could you please give me any information regarding this?

    Thursday, March 28, 2019 5:25 PM
  • Still I'm suffering with this issue.

    I posted with new title named "How to load configuration file from specific folder and save it to application path with different file name?".

    Could you please give me any information regarding this?

    Thursday, March 28, 2019 5:25 PM
  • Still I'm suffering with this issue.

    Then why have you marked the thread as solved ???
    Thursday, March 28, 2019 5:37 PM