473,473 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to add a stringformat in app.config

Spippo
15 New Member
Hi,

I want to create a string with string.format, but the format must be editable.
Therefor i want to add the format in app.config and read it from the program and enter the correct values in it.

This is my app.config-file:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-16" ?>
  2. <configuration>
  3.   <appSettings>
  4.     <!-- SimpleMailAddin settings -->
  5.          <!-- MailSender, SMTPServer and MailBodyFormat are required -->
  6.     <add key ="MailSender" value ="me@mydomain.com"/>
  7.     <add key ="SMTPServer" value ="VMEXCH.mydomain.com"/>
  8.          <!-- This is the foSystermatstring of the body of the message. Usable values : {0} = Event_ID  {1} = Event_Name  {2} = Event_StartDate  {3} = Event_EndDate  {4} = Event_Description -->
  9.     <add key="MailBodyFormat" value="Event Reminder\n\nEvent       : {1} ({0})\nStartdate   : {2}\nEnddate     : {3}\n\n{4}"/>    
  10.   </appSettings>
  11. </configuration>
  12.  
My code tries to fill in the string like this:
Expand|Select|Wrap|Line Numbers
  1. string body = System.Configuration.ConfigurationManager.AppSettings["MailBodyFormat"];
  2. body = string.format(body, Event_ID, Event_Name, Event_StartDate, Event_EndDate, Event_Description);
  3.  
If I run this code, my string "body" still is "Event Reminder\n\Event : {1} ...." and not {Event Reminder\n\nEvent : My event ..."

Any way to solve this?
Nov 13 '07 #1
2 3522
mzmishra
390 Recognized Expert Contributor
Is it giving any error?
I did something like this it works fine

<appSettings>
<add key="MyConnectionString" value="Driver={SQL Server};Server=myServerAddress;Database=myDataBase ;Uid={0};Pwd={1};"/>
</appSettings>

string myConnectionString = string.Empty;

myConnectionString = ConfigurationManager.AppSettings["MyConnectionString"];

myConnectionString = string.Format(myConnectionString, myUserId, myPassword);
Nov 13 '07 #2
Spippo
15 New Member
Hi,

Thanks for the quick reply.
It did work correctly, I made a mistake in my program.

I did have a problem with the newline '\n', this was just display as the text "\n" and not as a newline.
I solved this by replacing '\n' with {5} and set the sixth parameter as "\n".

Thanks
Nov 13 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: Maxim Khesin | last post by:
I want to have a config file with my python proggie, satisfying the following requirements: 1) support key->(value, default) 2) simple and intuitive to read and edit 3) easyly readable into a...
4
by: Fuzzyman | last post by:
There have been a couple of config file 'systems' announced recently, that focus on building more powerful and complex configuration files. ConfigObj is a module to enable you to much more *simply*...
0
by: John Richardson | last post by:
I have a DataGridLabelColumn I've made by overriding a DataGridColumnStyle object. (based on an MSDN article by Chris Sano). In the Paint method, I use a StringFormat object, and pass that to a...
3
by: Richard Lewis Haggard | last post by:
I have a test application that is calling an assembly that reads some strings out of a config file. Normally, this assembly supports a web application and the information can be read just fine....
13
by: Khodr | last post by:
Hello, I am using VS.NET 2003 and vb. I build my application MyApp and it generates MyApp.exe.config. So now MyApp.exe reads parameters from MyApp.exe.config. Great and no problem! I need to...
11
by: TARUN | last post by:
Hello All I need to ask about the configuration file in .NET, There are Two config File 1. Web Config 2. Machine config I understand the the usage of Web config , but not able to understand...
3
by: Jens Jensen | last post by:
Hello, I have a webservice that performs some financial calculations. I use String.Format("{0:n}) to presents the numbers in the culture specific format. This works fine on my dev machine which...
12
by: dbuchanan | last post by:
Hello, (Is this the proper newsgroup?) === Background === I am building a solution with two projects. One project is my data access layer which contains my DataSet as an xsd file. The XSD...
5
by: mmcd79 | last post by:
I built a VB.net application that makes use of a machine level DB connection string setting, and a user level starting location setting. The machine level setting and the default user based...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.