Storing many-to-one relationships in a .Config file


hi,

i'm trying write c# app read user permissions folders.  since not wish recompile app if changes desired user permissions, i'd store in app's .config file.  cannot see how cleanly though.

a custom .config file section looks like:

<configuration>    <configsections>      <sectiongroup name="mygroup">          <section name="mysection" type="system.configuration.namevaluesectionhandler, system, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934df89" />      </sectiongroup>      </configsections>    <mygroup>      <mysection>          <add key="mykey1" value="somesetting"/>  	</mysection>  	</mygroup>  </configuration>
nice if store many-to-one relationship (maybe if use different type?).  guess inside value attribute like:

<add key="mykey1" value="c:\mypath;nt authority\network service;read;write"/>

that's way can think of how it.

-charlie

this example may not looking for, maybe work. below code asumes few things.

1) have appsetting called "access"
2) have use characters not conflict file names or things of nature, doesn't accidently mess up.
3) have have static number of attributes each set. if max number 6 values possibly need and single key entry has 4 requirements, have represent empty spaces.

example access:

"c:\program files\*nt authority\network service*true*false|c:\*nt authority\network service*true*true|c:\users\user\*nt authority\network service*false*true"

example code:

private void parseaccess() {     string[] _keys = configurationmanager.appsettings.get("access").split('|');     foreach (string _key in _keys)     {         string[] _attribute = _key.split('*');         /*         here         example:                          string filepath = _attribute[0];         string usergroup = _attribute[1];         bool read = convert.toboolean(_attribute[2]);         bool write = convert.toboolean(_attribute[3]);                                         */     } }

again, don't know if looking for, need add addition access directory or ever app setting , have code ever want each entry.

**edit**

also, if not want write single app setting, can create independent keys , separate attributes within '|' character.

private void parseaccess() {     foreach (string _key in configurationmanager.appsettings)     {         string[] _attribute = configurationmanager.appsettings[_key].split('|');         /*         here         example:                          string filepath = _attribute[0];         string usergroup = _attribute[1];         bool read = convert.toboolean(_attribute[2]);         bool write = convert.toboolean(_attribute[3]);                                         */     } }



Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'