Double Backslash problem in a path.

Denaes

Well-known member
Joined
Jun 10, 2003
Messages
956
{"Could not find file C:\\myStuff\\VS.Net Programming\\C#.Net Programs\\MyProgram\\common run folder\\data.xml."}

Code:
            XmlDocument dataXML = new XmlDocument(); 
            string path = Application.StartupPath + @"\data.xml";
            MessageBox.Show(path);
            SkillsXML.Load(path);

MessageBox.Show shows it properly with only one backslash, but I get that error about the path not existing/cant find file and it shows double backslashes.

I know there are issues with strings and regular expressions in C#, but I thought the @ would remove that problem. Apparently Im not correct.

Anyone know a fix for this?
 
$10 says the file isnt in that folder, but in your \bin\Debug folder.
Youre using Application.StartupPath which points to where the EXE is (or your working directory) which is \bin\Debug by default.

-ner
 
@Cuffee: Your solution should be the same as his. You can use the @ to NOT have to double up the backslashes or just double them up. I think he had the file in the wrong place. Bad backslashes usually mean syntax errors - but his MessageBox showed the right path (at least, one that looked "good").

-ner
 
Yeah, I feel stupid. :(

I forgot that since I have 3 projects in the solution (the app, a control and a .dll/logic tier), I made a fourth folder for the output of all three when they build. I had put the .xml file inside of the build folder for the application and was thinking my string wasnt working properly.

Sorry for the stupid mistake, still getting used to C#.
 
Back
Top