Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

c# - 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 = "\Sambasun005admin_configest.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 = @"\Sambasun005admin_configest.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"
@"\sun005admin_configest.txt"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...