8 Replies - 1149 Views - Last Post: 03 April 2017 - 04:05 AM

#1 wtp  Icon User is offline

  • D.I.C Regular

Reputation: 26
  • View blog
  • Posts: 319
  • Joined: 08-December 11

What library is used for config files that are user editable

Posted 21 February 2017 - 02:10 PM

I saw this library the other day, but can't find it now. I want to create a config file that the user can edit after the program is installed. I don't mean the app or web.config because the program user can't edit those files.
Is This A Good Question/Topic? 0
  • +

Replies To: What library is used for config files that are user editable

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13482
  • View blog
  • Posts: 53,820
  • Joined: 12-June 08

Re: What library is used for config files that are user editable

Posted 21 February 2017 - 02:12 PM

Why not just any old file?

Text file, call it a fun extension, etc.
Was This Post Helpful? 1
  • +
  • -

#3 wtp  Icon User is offline

  • D.I.C Regular

Reputation: 26
  • View blog
  • Posts: 319
  • Joined: 08-December 11

Re: What library is used for config files that are user editable

Posted 21 February 2017 - 02:21 PM

I could do that but there's a library for it that might make it easier. I may just do that considering there's just one thing I want to read.
Was This Post Helpful? 0
  • +
  • -

#4 Thomas1965  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 275
  • Joined: 09-September 16

Re: What library is used for config files that are user editable

Posted 21 February 2017 - 03:05 PM

You could create a class with some public properties and use the XML or JSON serializer to load and save it.
Was This Post Helpful? 1
  • +
  • -

#5 wtp  Icon User is offline

  • D.I.C Regular

Reputation: 26
  • View blog
  • Posts: 319
  • Joined: 08-December 11

Re: What library is used for config files that are user editable

Posted 21 February 2017 - 05:00 PM

That's a good idea. I'll use one of them.
Was This Post Helpful? 0
  • +
  • -

#6 wtp  Icon User is offline

  • D.I.C Regular

Reputation: 26
  • View blog
  • Posts: 319
  • Joined: 08-December 11

Re: What library is used for config files that are user editable

Posted 22 February 2017 - 10:55 AM

Follow up question.
I'm writing the file to this folder Environment.SpecialFolder.CommonApplicationData . It writes to that file and works fine, but it throws the error: "Access to the path 'C:\ProgramData\myprogram\config.txt' is denied." Right now I'm just catching the exception and doing nothing. I thought the Environment.SpecialFolder.CommonApplicationData folder would always allow writes. Is there another folder that my program will be guaranteed to be able to write to? Or am I going to have to change the permission of this folder when the program is being installed as admin?
Was This Post Helpful? 0
  • +
  • -

#7 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13482
  • View blog
  • Posts: 53,820
  • Joined: 12-June 08

Re: What library is used for config files that are user editable

Posted 22 February 2017 - 12:17 PM

It's common so that probably presents and issue.

Have you tried:
Environment.SpecialFolder.ApplicationData or Environment.SpecialFolder.LocalApplicationData ? I want to say they are more friendly.
Was This Post Helpful? 1
  • +
  • -

#8 wtp  Icon User is offline

  • D.I.C Regular

Reputation: 26
  • View blog
  • Posts: 319
  • Joined: 08-December 11

Re: What library is used for config files that are user editable

Posted 22 February 2017 - 12:45 PM

Thank you that directory has the write permission I need and isn't throwing error.
Was This Post Helpful? 0
  • +
  • -

#9 Sam Hobbs  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 50
  • Joined: 01-April 17

Re: What library is used for config files that are user editable

Posted 03 April 2017 - 04:05 AM

I think you want to use the settings of properties. In Visual Studio, go to the project's properties then in the left click on "Settings". Edit the default name in the Name column and set the "Scope" to "User" (it will probably be User already). Then for Value you can specify a default. Note that there are many "types" available and .Net will ensure that the data is valid for the type you specify. The settings are stored in the App.config (XML) file in the project. When the project is built it will rename the file "yourapp.exe.config" where "yourapp" is your application's name. Then in your program use:

Properties.Settings.Default.Settingsyourname


Where "Settingsyourname" is the name you gave in the settings. You can get the current value with that and then set a new value with that. If the value has been changed then you need to save using:

Properties.Settings.Default.Save();


Note that there will be a different config file for each user that uses the application on the system. I have seen something about a machine.config file but I don't know anything more about that.

Note that the ProgramData folder is for data that is not specific to a user.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1