开发者

Get Path of a Static XML file in C#?

How do I read get the full path of a static XML file I added开发者_运维知识库 to my C# WCF project?


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.


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


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";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜