We help IT Professionals succeed at work.

How to read all appSettings (key/val) from config file?

netformx
netformx asked
on
1,625 Views
Last Modified: 2012-08-14
Hi,

I would like to store in Hashtable all appSettings  I have in my config file.

or even better: to store all key/value where key start with "***"

Comment
Watch Question

CERTIFIED EXPERT
Top Expert 2006

Commented:
A Hashtable is a programming object/construct so you must being using a programming language. Which one are you looking to use (although from your comment history it would be more likely to be ASP.net than Java, yes)?

Commented:
Well, the ConfigurationSettings.AppSettings Property is a NameValueCollection, so  it's a simple matter to iterate over the members, and build a hash table or do anything else you want.  And the NameValueCollection has the GetHashCode method.

See:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemconfigurationconfigurationsettingsclassappsettingstopic.asp
And:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemcollectionsspecializednamevaluecollectionmemberstopic.asp

I'm curious why you need to store these in a hash table--they're always accessible by key anyway.  Do you access these so often that performance is an issue?

Regards,
Mike Sharp

Author

Commented:
I just want all keys tha tstart with some prefix - do you have better idea than put all into hashtable and then iterate and select what you need? (I don't know a way to access key by its prefix, do you?)
Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.