Reputation: 5104
I have a windows phone 8 app which I want to upgrade to WP8.1 universal app. Isolated Storage is not supported in 8.1, how do I upgrade my isolated settings in such case?
Upvotes: 2
Views: 1431
Reputation: 782
The __ApplicationSettings file which contains the IsolatedStorageSettings will be located in the local folder of the app when it was updated through the store.
This is not the case when updating the app through Visual Studio, as it seems to have difficulties replacing a Silverlight app with a WinRT app.
You need to deserialize this file to any known objects, and the store the objects someplace else. The following code will fetch the IsolatedStorageSettings in a WinRT app:
public static async Task<IEnumerable<KeyValuePair<string, object>>> GetIsolatedStorageValuesAsync()
{
try
{
using (var fileStream = await ApplicationData.Current.LocalFolder.OpenStreamForReadAsync("__ApplicationSettings"))
{
using (var streamReader = new StreamReader(fileStream))
{
var line = streamReader.ReadLine() ?? string.Empty;
var knownTypes = line.Split('\0')
.Where(x => !string.IsNullOrEmpty(x))
.Select(Type.GetType)
.ToArray();
fileStream.Position = line.Length + Environment.NewLine.Length;
var serializer = new DataContractSerializer(typeof (Dictionary<string, object>), knownTypes);
return (Dictionary<string, object>) serializer.ReadObject(fileStream);
}
}
}
catch (FileNotFoundException)
{
// ignore the FileNotFoundException, unfortunately there is no File.Exists to prevent this
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
}
return new Dictionary<string, object>();
}
Upvotes: 0
Reputation: 864
ApplicationData.LocalSettings -- Gets the application settings container in the local app data store.
NameSpace : Windows.Storage
var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
// Create a simple setting
localSettings.Values["exampleSetting"] = "Hello Windows";
// Read data from a simple setting
Object value = localSettings.Values["exampleSetting"];
if (value == null)
{
// No data
}
else
{
// Access data in value
}
// Delete a simple setting
localSettings.Values.Remove("exampleSetting");
You can read documentation here
Upvotes: 1