thecureis
asked on
C# Express 2008 Write to App.Config
This is what I am trying to accomplish.
I need to store an API key and Username securely within a program with the ability to update it.
I have dabbled in C# years ago and am fairly descent in VB.NET, PHP, VBScript and other scripting languages.
From what I have read I should use the App.config file rather than an INI file due to security. i have added the entries to my App.Config (see code below) and can read them just fine. My script will first check those values, if either are null then open a form to enter the information.
I cannot for the life of me find how to save that information back to the app.config or app.config.exe file.
I have googled for many of hours and found references to ConfigurationManager which apparently is not valid in C# Express. I only have ConfigurationSettings.
C# 2008 Express .Net 3.5
I need to store an API key and Username securely within a program with the ability to update it.
I have dabbled in C# years ago and am fairly descent in VB.NET, PHP, VBScript and other scripting languages.
From what I have read I should use the App.config file rather than an INI file due to security. i have added the entries to my App.Config (see code below) and can read them just fine. My script will first check those values, if either are null then open a form to enter the information.
I cannot for the life of me find how to save that information back to the app.config or app.config.exe file.
I have googled for many of hours and found references to ConfigurationManager which apparently is not valid in C# Express. I only have ConfigurationSettings.
C# 2008 Express .Net 3.5
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="apiKey" value="##############" />
<add key="apiUsername" value="APIUsername" />
</appSettings>
</configuration>
C#
string strApiKey = Convert.ToString(ConfigurationSettings.AppSettings["apiKey"]);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I ended up figuring it out. I had to go to Project->Add Reference->system.configur ation
Since I will be creating a hybrid from both of your posts I am splitting the points.
Thank you both.
Since I will be creating a hybrid from both of your posts I am splitting the points.
Thank you both.
ASKER
I do have
using System.Configuration;
I believe that the ConfigurationManager was replaced with ConfigurationSettings in C#2008 Express Edition.
If I replace ConfigurationManager with ConfigurationSettings then i get the following errors.
The type or namespace name 'Configuration' could not be found (are you missing a using directive or an assembly reference?)
'System.configuration.Conf
The name 'ConfigurationUserLevel' does not exist in the current context
They type or namespace name 'AppSettignsSection' could not be found (are you missing a using directive or an assembly reference?)