How I add Username and password and Path here?

In values i store username and password i access this how?
Vishal GundageAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dustin SaundersDirector of OperationsCommented:
If I'm understanding, your question is how do I take the keys in AppSettings and store them to then use in the second item?

If you're building an array of strings that are different values (password, username, etc.) then you don't want to iterate through them in a for loop.  So what you are doing since you have it in a for loop is running that command each time and using the array position for each setting.

For example, if you have a string array of  values = { "username", "password", "\\\\path\\" } you would need to use:
ConnectionOptions conoptions = new ConnectionOptions();
conoptions.Username = values[0];
conoptions.Password = values[1];
ManagementPath path = new ManagementPath(values[2]);

Open in new window

But even if you line up the array, that's not a good way to handle this as if your code changes you are iterating through your appsettings in no special order and the order of the array could change, breaking your code. (so don't do that)

If you have keys in your AppSettings such as "Username" and "Password", instead get those values with something like:
conoptions.Username = ConfigurationManager.AppSettings["Username"];
conoptions.Password = ConfigurationManager.AppSettings["Password"];

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dustin SaundersDirector of OperationsCommented:
Appropriate information to resolve this issue.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.