Sign in to follow this  

Files, StorageDevice/StorageContainer

This topic is 1121 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been trying to find a solution to this for a few hours now and my Google foo is not doing the job.

 

I have a map editor, with a bunch of tiles. I want to serialize the entire Map class to a file for later loading, I can't for the love of me figure out how to get what every tutorial/blog/stackoverflow answer is talking about, the StorageDevice/StorageContainer.

 

Am I missing something here?

 

Even the code samples gave to me by my tutor asks for the StorageContainer:

public static void SaveHighScores(HighScoreData data, string filename)
{
    // Get the path of the save game
    string fullpath = Path.Combine(StorageContainer.TitleLocation, filename);
 
    // Open the file, creating it if necessary
    FileStream stream = File.Open(fullpath, FileMode.OpenOrCreate);
    try
    {
        // Convert the object to XML data and put it in the stream
        XmlSerializer serializer = new XmlSerializer(typeof(HighScoreData));
        serializer.Serialize(stream, data);
    }
    finally
    {
        // Close the file
        stream.Close();
    }
}

Where does File.Open start? Is it the root directory of the machine (User)?

Share this post


Link to post
Share on other sites

StorageContainer.TitleLocation gets you an absolute path to the directory that represents your game's storage location. Path.Combine combines this absolute path with the file name, which results in an another absolute path.

 

If File.Open is given an absolute path, it tries to respect it precisely. If a relative path is specified, however, the method will try to find the file relative to the executable of the process, or relative to the working directory of the process. The path relative to the executable cannot usually be assumed to be writable without administrative rights.

 

Put a breakpoint to the File.Open line to see the actual path.

Edited by Nik02

Share this post


Link to post
Share on other sites

This topic is 1121 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this