Tequila
Tequila

Reputation: 736

Getting an exception when working with directoryInfo in C# / XNA

Think I have a problem with my windows phone application. In my application I have a static method that returns me a collection of textures located in specific folder. When I launch my application on the WP 8 Emulator it`s worked very well, but when I launch it on the WP 7 emulator I get an exception with the message "directory not exist". But in fact that this directory is existing. Could anybody tell me why this happends ?

Here I attached my code:

namespace Hornbook_v2
{
    public static class ContentLoader
    {
        public static Dictionary<String, T> LoadTextures<T>(this ContentManager contentManager, string contentFolder)
        {
            //Load directory info, abort if none
            DirectoryInfo dir = new DirectoryInfo(contentManager.RootDirectory + "\\" + contentFolder);

            //  The exception is happends HERE!!!
            if (!dir.Exists)
                throw new DirectoryNotFoundException();

            //Init the resulting list
            Dictionary<String, T> result = new Dictionary<String, T>();

            //Load all files that matches the file filter
            FileInfo[] files = dir.GetFiles("*.*");
            foreach (FileInfo file in files)
            {
                string key = Path.GetFileNameWithoutExtension(file.Name);

                //result[key] = contentManager.Load<T>(contentManager.RootDirectory + "/" + contentFolder + "/" + key);
                result[key] = contentManager.Load<T>(contentFolder + "/" + key);
            }

            //Return the result
            return result;
        }    

    }
}

Upvotes: 1

Views: 338

Answers (1)

Aranda
Aranda

Reputation: 865

You could try using the IsolatedStorage API, even if just for that one DirectoryExists check this:

EDIT

If you do need to port it all to IsolatedStorage, this MSDN page may be of use:

Upvotes: 1

Related Questions