In a C# 2010 application, I am placing the location where a file is located in the directory strucutre in a sql server 2008 r2 in a varchar(500) column called file locagtion.
When the column has been updated in the sql server database, the column looks like the following:
D:\\test1\\10_29_2012\\customer1(pk12)\\
storage location comes from the following line of code:
string file_location = ConfigurationSettings.AppSettings["tLocation"] + @"\" + Format_Date + @"\" + CustomerName + "(" + pkgId + ")" + @"\";
I basically only want one backslash.
Can you tell me what I can do so the value in the database is stored with "\" instead of with "\\"?
Loading
VulpesPosted Oct 29, 2012, 2:39 PM
It therefore 'escapes' backslashes by doubling them. If this were not done, then the backslash would be the start of an 'escape sequence' such as \n, \r or \t which have special meanings in C# and other languages derived from C.
So, in other words, although the debugger is doubling the backslashes, in reality there's just one :)
Shivanand ArurPosted Oct 29, 2012, 2:43 PM
Basically "\" is a special. Character which is used with \n - for newline, \t for a tab.... VlC# does not allow "\" mark to be used without an @ sign or double slash... \\
There's a small concept called as Verbatim string which means when we are using such special characters... which in your case is "\" we have to use an @ or \\
You can see \\ in the debug mode since C# converts your single \ into multiple \\
Hope this helps U out.... If still confused... Try googling about Verbatim Strings...
Please mark the answer as accepted if ir helped
Thanks.... :)
dcPosted Oct 29, 2012, 2:22 PM
VulpesPosted Oct 29, 2012, 1:09 PM