问题
I was wondering if anyone here knows how to find the complete path (from the drive letter onwards) of a ContentManager instance. using this I could create a string with the right number of "..\" to append to the file path when I want to load a file from anywhere else on the computer (eg. from a registry key).
So basically I'm asking if there is a way.
回答1:
You may just want to use System.GetFolderPath with one of these locations, most likely Program Files. From there, you can navigate to your application's installation directory. You could also use .Load("\MyFolder\blah") which will load from the default disk (e.g. C:\MyFolder\blah.xnb or whatever).
If you want the path of your .exe file...
using System.IO;
using System.Windows.Forms;
//blah blah
string GetAppDir()
{
return Path.GetDirectoryName(Application.ExecutablePath);
}
来源:https://stackoverflow.com/questions/8696639/how-to-get-the-full-root-directory-of-a-contentmanager-in-xna-4-0