none
Erro: Operation not permitted - Isolated Storage RRS feed

  • Pergunta

  • Olá pessoal! Estou usando o Silverlight 4 e Visual Studio 2010 trial. Estou tentando salvar dados no IsolatedStorage com o seguinte código, e ao executar o projeto, dá um erro ( Operation not permitted)  na chamada de  m_appSettings = IsolatedStorageSettings.ApplicationSettings;

    Alguém sabe como resolver este problema? Muito Obrigada!!

     

     

    {System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted.
       at System.IO.IsolatedStorage.IsolatedStorageSecurityState.EnsureState()
       at System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication()
       at System.IO.IsolatedStorage.IsolatedStorageSettings.get_ApplicationSettings()
       at SilverlightApplication1.MainPage..ctor()
       at SilverlightApplication1.App.Application_Startup(Object sender, StartupEventArgs e)
       at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}

     

     

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.IO.IsolatedStorage;
    using System.IO;

    namespace SilverlightApplication1
    {
        public partial class MainPage : UserControl
        {
            IsolatedStorageSettings m_appSettings;

            public MainPage()
            {
                InitializeComponent();

                m_appSettings = IsolatedStorageSettings.ApplicationSettings;
                LoadSettingsIsolatedStorage();
                LoadOrCreateFileInIsolatedStorage();
            }

            private void button1_Click(object sender, RoutedEventArgs e)
            {
                if (!m_appSettings.Contains("Username"))
                    m_appSettings.Add("Username", String.Empty);

                m_appSettings["Username"] = textBox1.Text;           
            }

            private void LoadSettingsIsolatedStorage()
            {
                if (m_appSettings.Contains("Username"))
                    textBox1.Text = m_appSettings["Username"].ToString();           
            }

            private void LoadOrCreateFileInIsolatedStorage()
            {
                using (IsolatedStorageFile isoFile = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (!isoFile.FileExists("test.txt"))
                    {
                        using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("test.txt", FileMode.Create, isoFile))
                        {
                            using (StreamWriter sw = new StreamWriter(isoStream))
                            {
                                sw.Write("Este arquivo está no Isolated Storage...");
                            }
                        }
                    }
                    else
                    {
                        using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("test.txt", FileMode.Open, isoFile))
                        {
                            using (StreamReader sw = new StreamReader(isoStream))
                            {
                                label1.Content = "Conteúdo do arquivo 'test.txt': " + sw.ReadLine();
                            }
                        }
                    }
                }
            }
        }
    }

    quarta-feira, 5 de maio de 2010 10:56

Respostas

  • Olá , user_2006

    Falta o tipo de acesso FileAcess.Write:

    exemplo:

     private void GravarUsuario(string Nome,string User)
        {
          IsolatedStorageFile StorageFile = IsolatedStorageFile.GetUserStoreForApplication();
          try
          {
    
            using (IsolatedStorageFileStream StorageStream = new IsolatedStorageFileStream("texto.txt", FileMode.Create, FileAccess.Write, StorageFile))
            {
              using (StreamWriter sw = new StreamWriter(StorageStream))
              {
                sw.WriteLine(Nome+","+User);
              }
            }
    
    
          }
          catch (IsolatedStorageException ex)
          {
            MessageBox.Show(ex.Message);
          }            
          
        }

    Américo Arvani MCP/MCTS - WEB Se ajudou , marque como resposta. http://americoarvani.blogspot.com/
    • Marcado como Resposta Daniel Ferreira terça-feira, 13 de julho de 2010 17:54
    quarta-feira, 5 de maio de 2010 13:04

Todas as Respostas

  • Olá , user_2006

    Falta o tipo de acesso FileAcess.Write:

    exemplo:

     private void GravarUsuario(string Nome,string User)
        {
          IsolatedStorageFile StorageFile = IsolatedStorageFile.GetUserStoreForApplication();
          try
          {
    
            using (IsolatedStorageFileStream StorageStream = new IsolatedStorageFileStream("texto.txt", FileMode.Create, FileAccess.Write, StorageFile))
            {
              using (StreamWriter sw = new StreamWriter(StorageStream))
              {
                sw.WriteLine(Nome+","+User);
              }
            }
    
    
          }
          catch (IsolatedStorageException ex)
          {
            MessageBox.Show(ex.Message);
          }            
          
        }

    Américo Arvani MCP/MCTS - WEB Se ajudou , marque como resposta. http://americoarvani.blogspot.com/
    • Marcado como Resposta Daniel Ferreira terça-feira, 13 de julho de 2010 17:54
    quarta-feira, 5 de maio de 2010 13:04
  • Mas o erro aparece já ao tentar chamar:
     IsolatedStorageFile StorageFile = IsolatedStorageFile.GetUserStoreForApplication();



    {System.IO.IsolatedStorage.IsolatedStorageException: Operation not permitted.
       at System.IO.IsolatedStorage.IsolatedStorageSecurityState.EnsureState()
       at System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication()
       at System.IO.IsolatedStorage.IsolatedStorageSettings.get_ApplicationSettings()
       at SilverlightApplication1.MainPage..ctor()
       at SilverlightApplication1.App.Application_Startup(Object sender, StartupEventArgs e)
       at MS.Internal.CoreInvokeHandler.InvokeEventHandler(Int32 typeIndex, Delegate handlerDelegate, Object sender, Object args)
       at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)}

     


    quarta-feira, 5 de maio de 2010 13:56