Ir al contenido principal

26/12/2012 Usnado Isolated Storage en WP 7

Ejemplo para la siguiente pantalla:



Descargar código del siguiente Link Descarga codigo fuente

Imports System.IO.IsolatedStorage
Imports System.IO

Partial Public Class MainPage
    Inherits PhoneApplicationPage

    Dim miAlmacen As IsolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication
    Dim directorio As String
    Dim archivo As String
    Dim fileStream As IsolatedStorageFileStream
    ' Constructor
    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub btnDirectorio_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnDirectorio.Click
        directorio = txtDirectorio.Text
        miAlmacen.CreateDirectory(directorio)
    End Sub

    Private Sub btnFile_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnFile.Click        
        archivo = txtFile.Text
        fileStream = New IsolatedStorageFileStream(directorio & "\\" & archivo, IO.FileMode.OpenOrCreate, miAlmacen)

    End Sub

    Private Sub btnGuardar_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnGuardar.Click
        Using fileWriter As New StreamWriter(fileStream)
            fileWriter.WriteLine(txtTexto.Text)
        End Using

    End Sub

    Private Sub btnLeerFile_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnLeerFile.Click
        Dim texto As String = ""
        Using fileStream As IsolatedStorageFileStream = New IsolatedStorageFileStream(directorio & "\\" & archivo, IO.FileMode.Open, miAlmacen)
            Using fileReader As New StreamReader(fileStream)
                texto = texto & fileReader.ReadLine
            End Using
        End Using

        MessageBox.Show(texto, "mensaje", MessageBoxButton.OK)

    End SubEnd Class
PARA VER LA CREACION DE NUESTROS DIRECTORIOS Y ARCHIVOS HACEMOS USO DE LA HERRAMIENTA INSTALADA EN EL EMULADOR SDK DE WP

Entramos a la ventana de comandos CMD, buscamos el Tool del almacenamiento aislado en la ruta donde esta instalado nuestro emulador algo asi como la siguiente linea:

C:\Program Files\Microsoft SDKs\Windows Phone\v7.1\Tools\IsolatedStorageExplorerTool>

Una vez en esa ruta ponemos el siguiente comando


ISETool.exe dir <xd|de> <Product GUID>

donde XD: indica emulador
y Product GUID lo encontramos en el archivo WMAppManifest.xml, en una linea como la siguiente
<App xmlns="" ProductID="{cb64befd-4583-43ac-a5e4-d6185d6d8189}" Title="PhoneAppIsolatedStorage" RuntimeType="Silverlight" ...

Entonces nuestra linea de comando quedaria de la siguiente manera:
ISETool.exe dir xd cb64befd-4583-43ac-a5e4-d6185d6d8189



 
*******************************************************
USANDO EL PROGRAMA WP7 ISOLATED STORAGE EXPLORER

1. Agregamos referencia a la DLL que esta en una ruta como la siguiente:
C:\Program Files (x86)\WP7 Isolated Storage Explorer\Library

2. Vamos al archivo App.xaml de nuestro proyecto y agregamos la siguiente linea en el motodo Launching
Private Sub Application_Launching(ByVal sender As Object, ByVal e As LaunchingEventArgs)IsolatedStorageExplorer.
Explorer.Start("localhost")
End Sub

3. Agregamos tambien la siguiente linea de codigo
Private Sub Application_Activated(ByVal sender As Object, ByVal e As ActivatedEventArgs)IsolatedStorageExplorer.Explorer.RestoreFromTombstone()
End Sub
  4. Corremos nuestra aplicacion, vamos a menu ver >> Otras Ventanas >> WP7 Isolated Storaged ... en nuestro VS2010

Comentarios