Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error storing < and > characters in app.config file in C#

I want to store a sql query in app.config file which has < and > characters but file shows error 'expecting >' , have you come across this problem ?

like image 908
dnyan86 Avatar asked Aug 27 '12 13:08

dnyan86


People also ask

How do you exit ampersand in web config?

Use " &amp; " instead of "&".

Can DLL have config file?

Using configuration files in DLL is not trivial, but is very simple. Using configuration files in DLL is not trivial.


5 Answers

Just change the < and > to &lt; and &gt;.

like image 134
aquinas Avatar answered Oct 06 '22 06:10

aquinas


If you indeed need to put that query in the app.config, you can put it inside a CDATA section or you can escape those characters with &lt; and &gt;

like image 39
Daniel Hilgarth Avatar answered Oct 06 '22 06:10

Daniel Hilgarth


First, if you're storing SQL in the app.config you're probably doing something wrong. As @ChrisBint said, you should probably put this in an embedded resource file instead.

That being said, you should be able to correct the problem by replacing any special characters with a proper entity:

<  ... &lt;
>  ... &gt;

"  ... &quot;
like image 25
Joel Etherton Avatar answered Oct 06 '22 05:10

Joel Etherton


Store the SQL in a resource file rather than the app.config.

like image 39
ChrisBint Avatar answered Oct 06 '22 06:10

ChrisBint


(greater-than character) use "&gt"

Must be used for an attribute value, but > is acceptable as the content of an element as long as < does not precede it.

< (less-than character) - use "&lt"

Must be used for an attribute value, but < is acceptable as the content of an element as long as > does not follow it.

source - http://msdn.microsoft.com/en-us/library/ms748250.aspx

like image 42
DotNetUser Avatar answered Oct 06 '22 06:10

DotNetUser