Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unrecognized escape sequence

VS 2005 WinXP

I am writing an application that will connect to a samba share.

However, in my path I am getting an compile error:

unrecognized escape sequence

The path I am using is this:

string path = "\\Samba\sun005\admin_config\test.txt";

I have also tried the following using double backlashes:

string path = "\\Samba\\sun005\\admin_config\\test.txt";

However, the above compiles ok, but when it runs it complains "cannot find the path"

Also tried the following:

string path = @"\\Samba\sun005\admin_config\test.txt";

When I check in the debugger I get the following string

\\Samba\\sun005\\admin_config\\test.txt

I get access denied in my exception. Now that I am thinking about it. I haven't set the username and password. I think that is my problem.

like image 489
ant2009 Avatar asked Dec 02 '22 04:12

ant2009


1 Answers

A UNC path should just include the machine name, the share name, an the path relative to the share point (inclusion of a "samba" scheme is not necessary). In the case of the machine name being sun005, either of the two following should work:

"\\\\sun005\\admin_config\\test.txt"
@"\\sun005\admin_config\test.txt"
like image 142
Andy Hopper Avatar answered Dec 23 '22 03:12

Andy Hopper