Reading app.config file c#

Hello All,

can anybody help me on the below .

I am trying to read config value from the user control on button click .
I can read a xml file instead by getting the rhp path like
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase and read the file .

But I am bit curious to know is there anything else I need to do or it wont work in the Rhino solutions

public partial class DetailsDock : UserControl

private  void  BUttontInfo_Click(object sender, EventArgs e)
    {

var url = ConfigurationManager.AppSettings[“url”];

thanks

Hi @nevin.mathew,

Why don’t you just use RhinoCommon’s PersistentSettings class? There is a PersistentSettings object on your plug-in object and on every Command object.

For example:

private void button1_Click(object sender, EventArgs e)
{
  var url = MyTestPlugIn.Instance.Settings.GetString("url");

  // TODO...

  MyTestPlugIn.Instance.Settings.SetString("url", url);
}

– Dale

Thanks Dale for the quick reply.

What I can understand is persistent setting class is similar like a ReadOnly variables.
This values can only set fro code , if we need to update then we need to make code changes.
If we need to populate the persistent setting class values from a config is is there any way which is common used for Rhino plugin creation.

As I tried I can read a xml file from the location using the System.Reflection.Assembly.GetExecutingAssembly().GetName().
But bit curious to know is there any particular reason why the ConfigurationManager.AppSettings is not able to read a app.config file .

once again thanks a lot for your response, have a nice day head.

Rhino’s persistent settings class allows your plug-in and plug-in command to both read and write settings to the plug-in’s settings file.

The problem with using the traditional .NET config file is that it is often in the same folder as the calling assembly, which is often a location that users don’t have rights to write to.

Have you tried using the persistent setting feature I referenced above?

– Dale

Thanks Dale.
I can only see the option to add one type of setting file in the add new item option and I tried to read like the below and pfa the screen shot for your reference.

var pathFromPersistentSettingFile = MyPlugIn.Instance.Settings.GetString(“path”);
it didnt worked.

can you please share how to add a settings file .

I am able read and set the value on runtime, but my requirement is to read from a file because we have new value to read from and udpate the file locally

settingKeyvalue

I am not sure about adding a file from the visual studio IDE.

I tried the below code and I am able to save it locally , but its getting saved to to the user folder like this

C:\Users******\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins*pluginname* (6cef8511-a474-4679-af71-f4e919de7a76)\settings

savesetting dont have a option to give the filename or filepath.

MyPlugIn.Instance.Settings.SetString(“path”, “testpath”);
MyPlugIn.Instance.SaveSettings();