Posted By

pckujawa on 11/19/09


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

ovuncgursoy
Priestd09


Isolated Storage in .NET (Reading, Writing, and Deleting a File; Checking Available Space)


 / Published in: C#
 

URL: http://windowsclient.net/learn/video.aspx?v=90634

Code taken from the video in the URL.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.IO;
  10. using System.IO.IsolatedStorage;
  11.  
  12.  
  13. //'.NET Framework Developer's Guide
  14. //'Introduction to Isolated Storage
  15. //'http://msdn.microsoft.com/en-us/library/3ak841sy.aspx
  16.  
  17. //'Isolation by User and Assembly.
  18. //'Isolation by User, Domain, and Assembly.
  19. //'http://msdn.microsoft.com/en-us/library/eh5d60e1.aspx
  20.  
  21. //'Where depends on Operating System
  22. //'VISTA
  23. //'Roaming-enabled stores = <SYSTEMDRIVE>\Users\<user>\AppData\Roaming
  24. //'Nonroaming stores = <SYSTEMDRIVE>\Users\<user>\AppData\Local
  25. //'Pasted from <http://msdn.microsoft.com/en-us/library/3ak841sy.aspx>
  26.  
  27.  
  28.  
  29. namespace HDI_WinForms_IsolatedStorage
  30. {
  31. public partial class Form1 : Form
  32. {
  33. public Form1()
  34. {
  35. InitializeComponent();
  36. }
  37.  
  38. private void ButtonCreateFile_Click(object sender, EventArgs e)
  39. {
  40. IsolatedStorageFile isolatedStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
  41. IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("TestStore.txt", FileMode.Append, FileAccess.Write, isolatedStore);
  42.  
  43. using (StreamWriter writer = new StreamWriter(isoStream))
  44. {
  45. writer.WriteLine("The Data " + DateTime.Now.ToShortTimeString());
  46. }
  47. }
  48.  
  49. private void ButtonReadIsoFile_Click(object sender, EventArgs e)
  50. {
  51. IsolatedStorageFile isolatedStore = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
  52. IsolatedStorageFileStream isolatedStream = new IsolatedStorageFileStream("TestStore.txt", FileMode.Open, isolatedStore);
  53. using (StreamReader reader = new StreamReader(isolatedStream))
  54. {
  55. this.RichTextBox1.Text = reader.ReadToEnd();
  56. }
  57. }
  58.  
  59. private void ButtonSpaceAvailable_Click(object sender, EventArgs e)
  60. {
  61. IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly | IsolatedStorageScope.Domain, null, null);
  62. ulong spaceAvailable = isolatedStorage.MaximumSize - isolatedStorage.CurrentSize;
  63. this.LabelSpaceAvailable.Text = spaceAvailable.ToString();
  64.  
  65. }
  66.  
  67. private void ButtonDeleteIsoFile_Click(object sender, EventArgs e)
  68. {
  69. IsolatedStorageFile isolatedStorage;
  70. isolatedStorage = IsolatedStorageFile.GetStore(IsolatedStorageScope.User | IsolatedStorageScope.Assembly, null, null);
  71. isolatedStorage.DeleteFile("TestStore.txt");
  72. }
  73. }
  74. }

Report this snippet  

You need to login to post a comment.