tags:

views:

61

answers:

3

How do I read get the full path of a static XML file I added to my C# WCF project?

A: 

When you added it, the file was copied into the directory where your csproj file is.

Steven Sudit
+1  A: 

What is a "static XML file" for you?

You can use Assembly.GetEntryAssembly().Location in combination with Path.Combine if you want to access a file in the same directoy as your executable (or in any subdirectory).

Or did you compile it as a resource? Then, you can't access it via the file system.

winSharp93
This answer is as correct as mine: obviously, none of us can be sure what the questioner actually meant.
Steven Sudit
A: 

If you're at development stage, you probably just hit F5 and your program runs.

It run from bin\debug folder, so you need to go up two levels and you'll be at your project root directory. If you created a folder to keep your static files, you'll need to do:

string myStaticXmlFilePath = @"..\..\StaticFiles\MyStaticXmlFile.xml";
Rubens Farias
I would imagine that the file is set to be copied to the output directory.
Steven Sudit
yes, but that setting isn't default
Rubens Farias
True enough. However, without this, there's no guarantee that the file will be available after installation.
Steven Sudit
True enough! =)
Rubens Farias