[WP-WS] Save file, HELP!

Hi, I am trying to convert my work to Windows Phone and Windows Store, but I cannot write a routine to write and read a binary file for save game and save the status game. There is an documentations to do this? There are samples?

Thanks!!

What is WPS? How are you writing to binary file?

sorry I have wrong word. WP and WS, Windows Phone and Windows Store!

Still the question remains, how are you writing/reading.

I have used FileStream but at runtime the application crashes…

What is the callstack of the crash? Also show some code

I could be wrong, but I think you have to use a different api for windows store apps… (yes?)

https://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.storagefile.aspx

Sorry for late:

this is the code test to write a file… but when I try to read I have an error:

#if NETFX_CORE

public async void WriteBuffer() {
var _Name = _fileName;
var _Folder = Windows.Storage.ApplicationData.Current.LocalFolder;
var _Option = Windows.Storage.CreationCollisionOption.ReplaceExisting;
var _File = await _Folder.CreateFileAsync(_Name, _Option);
if (_File != null)
{
Debug.Log("*** Create file: " + _Name);
}
else
return;

byte[ ] buffer = new byte[_length];
System.Buffer.BlockCopy(_buffer, 0, buffer, 0, _length);
await Windows.Storage.FileIO.WriteBytesAsync(_File, buffer);
}

#endif

for read:

#if NETFX_CORE

public async void ReadBuffer() {

var _Name = _fileName;
var _Folder = Windows.Storage.ApplicationData.Current.LocalFolder;
var _File = await _Folder.GetFileAsync(_Name);

if (_File != null)
{
Debug.Log(“*** Open file: " + _Name);
}
else {
Debug.LogError(”*** Error open file: " + _Name); <<<< this is the error message. So GetFileAsync fails.
return;
}

IBuffer buffer = await FileIO.ReadBufferAsync(_File);
using (DataReader dataReader = DataReader.FromBuffer(buffer))
{
dataReader.ReadBytes(_buffer);
if(_buffer == null) {
Debug.LogError("*** Cannot open file for read: " + _Name);
}
}
}

#endif

Thanks for help!

How the error looks like and what line throws it, there are multiple places here which output an “error”

inside ReadBuffer() fails _Folder.GetFileAsync(_Name);

but, my questione is: is it a right way to save and write a file? Thanks!!!

There are many methods on how to write/read file, from my perspective this code looks complicated, but looks okey.

There are easier ways on how to do it though, for ex., try using Unity - Scripting API: File

Thanks! I try it!