1

I am trying to store a string or nvarchar(500) in SQL. When I pass a full file path as a string parameter, there is an error unrecognized escape sequence.

Since path is not an usual param that this stored procedure expects, how can I open this possibility so it can accept string such as c:\foldername\subfoldername. Am I suppose to add @ at the begging of a string or use a StringBuilder?

Thanks

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
mko
  • 6,638
  • 12
  • 67
  • 118
  • possible duplicate of [Unrecognized escape sequence for path string containing backslashes](http://stackoverflow.com/questions/1302864/unrecognized-escape-sequence-for-path-string-containing-backslashes) – JasonMArcher Feb 05 '15 at 00:04

2 Answers2

1

Since backslash is considered as a special character(escape), it's causing the issue. Use / or \\ in the path as:

      c:/foldername/subfoldername
      c:\\foldername\\subfoldername

OR as you said, use @ in the front as :

     @"c:\foldername\subfoldername"

EDIT: For Javascript, I will simply replace the \ to / as below:

     path = path.split("\\").join("/");
Yogendra Singh
  • 33,927
  • 6
  • 63
  • 73
  • this field is used as a notice field, and i cannot expect from user to know that. as an alternative, using regex to fix this is overkill. – mko Nov 30 '12 at 14:35
  • 1
    @John AS you mentioned, you may want to put `@` in the front as other option. – Yogendra Singh Nov 30 '12 at 14:49
  • but what if I am passing it from a javascript to a webservice? How to prepare this string in JS for a webservice? – mko Dec 03 '12 at 12:18
  • 1
    @John If javascript, then you can easily replace the `\` with `/` by `path = path.split("\\").join("/");` before passing the values to next layers of your application. – Yogendra Singh Dec 03 '12 at 13:48
1

You can also escape the backslash() by adding the @ to the front of the string for example

@"This\Is\Some\Path"
Andre Lombaard
  • 6,985
  • 13
  • 55
  • 96