FileIO.ReadTextAsync
always returns empty string ("") in Windows 8 application. Am working on Universal application and to note is that, FileIO.ReadTextAsync
returns string when deploying in Windows Phone application but returns empty string in Windows 8 application? Here is my code.
async Task<string> LoadStatus(String listFileName)
{
StorageFile localFile = await ApplicationData.Current.LocalFolder.GetFileAsync(listFileName);
string configData = await FileIO.ReadTextAsync(localFile);
return configData;
}
And am calling this function as,
string result = await LoadStatus(AppConstants.VeryHappyStatusListName);
And listFileName is "FileName.xml".
I have gone through these (post1 and post2) posts and followed the same procedure but still returns null?
Also one thing to note that, Am getting error while writing data. Sometime it writes data perfectly and sometimes i get error while writing.
Here is my save to storage method.
async public void SaveStatus(List<Datum> list, String listFileName)
{
try
{
string localData = ObjectSerializer<List<Datum>>.ToXml(list);
if (!string.IsNullOrEmpty(localData))
{
StorageFile localFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(listFileName, CreationCollisionOption.ReplaceExisting);
if (localFile != null)
{
//await Task.Delay(3000);
await FileIO.WriteTextAsync(localFile, localData);
}
}
}
catch (Exception ex)
{
DebugPrint(ex.Message.ToString());
DebugPrintLocation("SaveStaus", "SessionStorage");
}
}
Am following this link : https://code.msdn.microsoft.com/windowsapps/CSWinStoreAppSaveCollection-bed5d6e6
Also important thing to note that, if I check each line using breakpoints everything goes fine. I can able to save large list and retrieve. But couldn't control without breakpoints.