Search code examples
c#xnaxna-4.0filepath

How to get the full root directory of a ContentManager in XNA 4.0


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.


Solution

  • 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);
    }