Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

$
0
0

I am serializing a file in Windows 8.1 preview and I believe the behavior of the storage file class has changed.

Before when I used CreationCollisionOption.ReplaceExisting the serialization would "replace" the existing file with data from the new serialization.  Now nothing gets serialized, so the "existing" file now gets replaced with a 0 byte file.  The way I read ReplaceExisting is if the file exists, replace it with a new one.

OpenIfExists actually writes data to the file.

public static async Task SerializeObjectToFileAsync<T>(T objectToSerialize, string fileName )
{
	StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);
	var serializer = new DataContractSerializer(typeof(T));

	using (IRandomAccessStream raStream1 = await file.OpenAsync(FileAccessMode.ReadWrite))
	{
		serializer.WriteObject(raStream1.AsStream(), objectToSerialize);
	}
}



Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>