Created
February 16, 2014 20:57
-
-
Save GSonofNun/9040551 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task ObjectToFile(Object obj, string fileName, string path = null) | |
{ | |
string json = await Task.Factory.StartNew(() => JsonConvert.SerializeObject(obj)); | |
StorageFolder sf = null; | |
if (path != null) | |
{ | |
sf = await ApplicationData.Current.LocalFolder.GetFolderAsync(path); | |
} | |
else | |
{ | |
sf = ApplicationData.Current.LocalFolder; | |
} | |
StorageFile file = await sf.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); | |
using (StreamWriter sw = new StreamWriter(await file.OpenStreamForWriteAsync())) | |
{ | |
await sw.WriteAsync(json); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment