Windows.storage namespace in monogame 3.8

Hello,

In my previous windows desktop projects (VS2017 + monogame 3.7.1) I would place “using Windows” at the top and then access Windows.Storage to read and write game save data

e.g. “await Windows.Storage.FileIO.WriteTextAsync(_File, fileContents);”

I can no longer call to Windows via “using Windows” and can no longer access Windows.Storage with the new version of monogame. What alternatives can I use?

Why not use System.IO.File?

1 Like

Thanks I used this tutorial

And since I cant write to C it seems to default to bin\Debug\netcoreapp3.1 for the location of the files i am reading and writing

If you do not specify a path when saving, then the file will be saved in the current working directory (which is normally the location of the executable).

Same for loading, if you don’t specify the full path then it assumes the current working directory.

To save a file you would do something like this:

System.IO.File.WriteAllText(@"C:\Temp\MyTextFile.txt", "The text to write to the file");

to read it

string myText = "";

myText = System.IO.File.ReadAllText(@"C:\Temp\MyTextFile.txt");

You need to be aware of where you are trying read and write to. Some locations may require administrator privileges and will throw an exception if you don’t have access.

I prefer to save all settings in the users Application Data path.

You can get that path with this:

string path = "";
path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);