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

VulpesRank #55 · 29.2K reputationPosted Oct 29, 2012, 10:39 AM EDT
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 :)
VulpesRank #55 · 29.2K reputationPosted Oct 29, 2012, 9:09 AM EDT
dcRank #2,247 · 627 reputationPosted Oct 29, 2012, 10:22 AM EDT
Shivanand ArurRank #920 · 2.3K reputationPosted Oct 29, 2012, 10:43 AM EDT
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.... :)