CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    How to make a config file accessible to many assemblies?

    in my project where I have a c# gui and a two dlls, one in c# and the other in c++/cli I have to be able to read/write the same config file but I don't know how to do it. currently my app is single threaded, but who knows maybe I make it multithreaded, what then? I guess I will have to use locks. please, give me some clues.

    how many different configs are there at all? I know only app configs that sit in the same folder as the application and user configs somewhere else in the user profile folders... do you know other types?
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: How to make a config file accessible to many assemblies?

    If you plan to write, understand that by default you won't have write permissions to the folder that contains the config file on the newer OS's (Vista and above).

    If you need to read/write user data, then use a Settings file.

    Btw, what kind of data are you planning on working with?

  3. #3
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: How to make a config file accessible to many assemblies?

    for now it will be only strings, with last folder used, or some window positions. by saying that I don't know how to do it I meant that I don't know which way to choose. I know how to read config files in .net (those in xml format). but how would you do it so that all three assemblies can read/write it. would you create another assembly with static methods that would read the config? or perhaps you would rather write non-static methods and pass an instance of the config reader to instances of other assemblies or classes within it?
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  4. #4
    Join Date
    Jul 2006
    Posts
    297

    Re: How to make a config file accessible to many assemblies?

    Quote Originally Posted by memeloo View Post
    for now it will be only strings, with last folder used, or some window positions. by saying that I don't know how to do it I meant that I don't know which way to choose. I know how to read config files in .net (those in xml format). but how would you do it so that all three assemblies can read/write it. would you create another assembly with static methods that would read the config? or perhaps you would rather write non-static methods and pass an instance of the config reader to instances of other assemblies or classes within it?
    Sounds like you would be better off just using a settings file not a config file. However, if you're using a .config file for an application and your application has 3 .dlls loaded in it. Those .dlls will read from the same .config file as their parent application.

    If that doesn't do what you want then try.

    Code:
    ConfigurationManager.OpenExeConfiguration(String exePath)
    However I don't think .config files make a lot of sense in your situation.

  5. #5
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: How to make a config file accessible to many assemblies?

    thx for pointing this out @monalin, I know there are config and setting files but I never thought about the differences, I've been just using app.configs until now... settings sounds to be a better solution indeed.

    http://social.msdn.microsoft.com/For...a-b4eef593b9a3
    http://social.msdn.microsoft.com/For...e-754d2c174a94
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured