Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7887387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:34:00+00:00 2026-06-03T05:34:00+00:00

I want to use a custom path for a user.config file, rather than have

  • 0

I want to use a custom path for a user.config file, rather than have .NET read it from the default location.

I am opening the file like this:

ExeConfigurationFileMap configMap = new ExeConfigurationFileMap();
configMap.ExeConfigFilename = String.Format("{0}\\user.config",AppDataPath);
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.PerUserRoamingAndLocal);

But I can’t figure out how to actually read settings out of it, I get a compile error saying that the values are inaccessible when I try to get a value through AppData or ConfigurationSection.

Do I need to create some sort of a wrapper class to consume the data properly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:34:01+00:00Added an answer on June 3, 2026 at 5:34 am

    I was recently tasked with a similar problem, I had to change the location of where settings files were read from the default location in AppData to the Application directory. My solution was to create my own settings files that derived from ApplicationSettingsBase which specified a custom SettingsProvider. While the solution felt like overkill at first, I’ve found it to be more flexible and maintainable than I had anticipated.

    Update:

    Sample Settings File:

    public class BaseSettings : ApplicationSettingsBase
    {
        protected BaseSettings(string settingsKey)
           { SettingsKey = settingsKey.ToLower(); }
    
    
        public override void Upgrade()
        {
             if (!UpgradeRequired)
                 return;
             base.Upgrade();
             UpgradeRequired = false;
             Save();
        }
    
    
        [SettingsProvider(typeof(MySettingsProvider)), UserScopedSetting]
        [DefaultSettingValue("True")]
        public bool UpgradeRequired
        {
             get { return (bool)this["UpgradeRequired"]; }
             set { this["UpgradeRequired"] = value; }
        }
    }
    

    Sample SettingsProvider:

    public sealed class MySettingsProvider : SettingsProvider
    {
        public override string ApplicationName { get { return Application.ProductName; } set { } }
        public override string Name { get { return "MySettingsProvider"; } }
    
    
        public override void Initialize(string name, NameValueCollection col)
             { base.Initialize(ApplicationName, col); }
    
    
        public override void SetPropertyValues(SettingsContext context, SettingsPropertyValueCollection propertyValues)
        {
           // Use an XmlWriter to write settings to file. Iterate PropertyValueCollection and use the SerializedValue member
        }
    
    
        public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection props)
        {
           // Read values from settings file into a PropertyValuesCollection and return it
        }
    
    
        static MySettingsProvider()
        {
            appSettingsPath_ = Path.Combine(new FileInfo(Application.ExecutablePath).DirectoryName, settingsFileName_);
    
            settingsXml_ = new XmlDocument();
            try { settingsXml_.Load(appSettingsPath_); }
            catch (XmlException) { CreateXmlFile_(settingsXml_); } //Invalid settings file
            catch (FileNotFoundException) { CreateXmlFile_(settingsXml_); } // Missing settings file
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use Custom URL Scheme to transfer data from application to other
I want to use a custom template file which shoud use the base layout
I'm currently investigating the possibility to use custom attributes derived from ActionFilterAttribute. I want
I have a custom UserControl called (for instance) MyPanel, and I want to use
What I want to do is use google analytic's custom event tracking from within
I have a user define class inside my zend application(as default) application/library/Custom_/Custom_Test.php I want
I want to use a header file, its included as #include <custom.h> how can
I want to use custom exception handling, for example instead of using (Exception ex)
I want to use a custom property to interact between controllers. Or do I
I want to use a custom class that could handle querying easily. Are there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.