view raw
NewCallum NewCallum - 6 months ago 40
C# Question

Why does my file directory include '/bin'?

I'm trying to find a file in a settings folder in my application. I have a xml file there. When I run the following code:

XDocument xDoc = XDocument.Load(@"..\settings\Settings.xml");

I get the
and the exception says not found at
, instead of above. I even tried the full root directory to see the issue,
but it still includes a bin folder?

How can I have it so it doesn't include the


By default, the build results in Visual Studio are saved in a folder like bin\Debug. Since you use a relative path that jumps one folder higher, you get yourProjectFolder\bin\settings\Settings.xml. That file doesn't exist, since it's presumably in the project folder, not the bin folder.

The typical way to deal with this is to make sure the files that are supposed to be a part of the content actually have Build Action set to Content.

Using a rooted path definitely works - most likely, you made a mistake somewhere; either the path isn't rooted at all, or you're doing something like interpreting the path as an URI rather than a file path. XDocument.Load takes a URI, not a file path - the proper way to reference an absolute path on the filesystem would be file://C:/ThePath/Settings/Settings.xml.