954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Getting value from txt File in App.Config

Hi Folks,

I am trying to make default AppSettings in my App.Config.

My Program, or part of it, requires an email template and I wish to save this template within a HTML File on my HDD. In my App.Config, I simply want to specify multiple keys such as Subject, Recipient etc and then get the value for each of those keys from a file, where the file will look something like this:

<html>
 <head>
 </head>
 <body>
  <p><b>Name:</b> {%Name%}</p>
  <p><b>Job Title:</b> {%JobTitle%}</p>
  <p><b>Address Line 1:</b> {%AddressLine1%}</p>
  <p><b>Address Line 2:</b> {%AddressLine2%}</p>
  <p><b>Address Line 3:</b> {%AddressLine3%}</p>
  <p><b>City:</b> {%City%}</p>
  <p><b>County:</b> {%County%}</p>
  <p><b>Postcode:</b> {%Postcode%}</p>
  <p><b>Telephone:</b> {%Telephone%}</p>
  <p><b>Fax:</b> {%Fax%}</p>
  <p><b>Comments:</b> {%Comments%}</p>
 </body>
</html>


the [%....%] tags are place-holders for actual data. Again, the tasks here is to get these data from my C# App.Config program.

Any help is appreciated.

Usmaan
Junior Poster in Training
63 posts since Mar 2010
Reputation Points: 17
Solved Threads: 0
 

App.Config is probably a bad place to put this information as it's not designed to be variable.

if you still wish to go that way, it's simply ConfigurationManager.AppSettings["keyname"]

Ketsuekiame
Master Poster
752 posts since May 2010
Reputation Points: 349
Solved Threads: 107
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: