IsolatedStorage Manager


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public static class IsolatedStorageCacheManager<T>
  2. {
  3. public static void Store(string filename, T obj)
  4. {
  5. IsolatedStorageFile appStore = IsolatedStorageFile.GetUserStoreForApplication();
  6.  
  7. using (IsolatedStorageFileStream fileStream = appStore.OpenFile(filename, FileMode.Create))
  8. {
  9. DataContractSerializer serializer = new DataContractSerializer(typeof(T));
  10. serializer.WriteObject(fileStream, obj);
  11. }
  12. }
  13. public static T Retrieve(string filename)
  14. {
  15. T obj = default(T);
  16. IsolatedStorageFile appStore = IsolatedStorageFile.GetUserStoreForApplication();
  17. if (appStore.FileExists(filename))
  18. {
  19. using (IsolatedStorageFileStream fileStream = appStore.OpenFile(filename, FileMode.Open))
  20. {
  21. DataContractSerializer serializer = new DataContractSerializer(typeof(T));
  22. obj = (T)serializer.ReadObject(fileStream);
  23. }
  24. }
  25. return obj;
  26. }
  27. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.