Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add newline character in app.config?

Tags:

c#

app-config

I'm not getting as how to write a message in app.config which consists of two or more lines. My usual code in config file is :

add key="msg_test" value="This is test message."        

And I read it in c sharp code like :

ConfigurationSettings.AppSettings[msg_test]; 

And I want to write something like

add key="msg_test"      value="This is test message \n are you sure you want to continue?" 
like image 322
quitprog Avatar asked Apr 26 '12 10:04

quitprog


People also ask

Is it possible to add a new line to an app?

However, you should be able to do it via API. e.g. try this: Add an App Setting with a new line, e.g. "test": "1234 5678" Show activity on this post. You can do it through Azure PowerShell task, but just remain newline symbol, the value won’t be in multiple lines, for example:

How do I create an application config file in Visual Studio?

On the menu bar, choose Project > Add New Item. The Add New Item dialog box appears. Expand Installed > Visual C# Items, and then choose the Application Configuration File template. In the Name text box, enter a name, and then choose the Add button. A file named app.config is added to your project.

How do I add a copy of my App config file?

When you build your project, the development environment automatically copies your app.config file, changes the file name of the copy to match your executable, and then moves the copy to the bin directory. On the menu bar, choose Project > Add New Item. The Add New Item dialog box appears.


2 Answers

You can just use line breaks in the value:

add key="msg_test" value="This is test message." 

You can also use XML encoded characters:

add key="msg_test" value="This is
test message." 

(I have tested both, and they work.)

like image 163
Guffa Avatar answered Sep 20 '22 07:09

Guffa


The XML escape for newline is 
, so this should work:

<add key="msg_test"  value="This is test message &#xA; are you sure you want to continue?"> 
like image 45
Anders Abel Avatar answered Sep 19 '22 07:09

Anders Abel