# Files, StorageDevice/StorageContainer

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

## 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 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

1. 1
2. 2
Rutin
25
3. 3
4. 4
5. 5

• 10
• 13
• 19
• 14
• 9
• ### Forum Statistics

• Total Topics
632942
• Total Posts
3009340
• ### Who's Online (See full list)

There are no registered users currently online

×