2013-12-21 95 views
1

我知道這個問題已經被問了很多次,但我已經幾乎嘗試了一切,但沒有運氣。所以請幫助。IsolatedStorageFileStream不允許操作 - WP7 C#

有些全局變量:

private string _DirectoryForLogin = "LoginFiles", _FileForLogin = "Login.startup"; 
private IsolatedStorageFile _GlobalAccessRight = IsolatedStorageFile.GetUserStoreForApplication(); 

_DirectoryForLogin店,存儲登錄信息和_FileForLogin商店TXT保存爲.STARTUP(我不認爲這是問題)文件的目錄名。

後來InitializeCompolnent()我這樣做後:

using(_GlobalAccessRight){ 
      //Checking if directory exists; case when user had already been logged in. 
      if (_GlobalAccessRight.DirectoryExists(_DirectoryForLogin)) 
      { 
       //Check if login startup file is already created. 
       if (_GlobalAccessRight.FileExists(_DirectoryForLogin + "\\" + _FileForLogin)) 
       { 
        //Not of much concern for you people. 
        _UserNameLabel.Text = "Please wait.... Logging in."; 
        _UserNameHolder.BorderThickness = new Thickness(0); 
        _UserNameHolder.IsEnabled = false; 
        _PasswordLabel.Text = ""; 
        _PasswordHolder.BorderThickness = new Thickness(0); 
        _PasswordHolder.IsEnabled = false; 
        _LoginButton.BorderThickness = new Thickness(0); 
        _LoginButton.Content = ""; 
        _LoginButton.IsEnabled = false; 

       } 
       else 
        _GlobalAccessRight.CreateFile(_DirectoryForLogin + "\\" + _FileForLogin); 
       //This part basically only creates the file, if directory was already existing. 
      } 
      else 
      { 
        //Creates directory as well as file. 
        _GlobalAccessRight.CreateDirectory(_DirectoryForLogin); 
        _GlobalAccessRight.CreateFile(_DirectoryForLogin + "\\" + _FileForLogin); 

      } 
     } 

事情到現在工作的罰款。問題是,如果我在創建目錄後嘗試刪除任何目錄,它會向我發送一個錯誤消息:「IsolatedStorage不允許操作」。但是我暫時解決了這個問題,只需關閉我的模擬器,以便獲得新的IsolatedStorage位置。

接下來我的文字和密碼箱取來自用戶的輸入,並超越了這個代碼寫他們上的一個文件:

 using(_GlobalAccessRight){ 
      //I have also tried by giving the FileShare argument below. 
      using(IsolatedStorageFileStream WritingStreamForLoginInfo = new IsolatedStorageFileStream(_DirectoryForLogin + "\\" + _FileForLogin, FileMode.OpenOrCreate, FileAccess.ReadWrite, _GlobalAccessRight)){ 
       using(StreamWriter WritingLoginInfo = new StreamWriter(WritingStreamForLoginInfo)){ 
        String _LoginCredentials = "UserName: "; 
        _LoginCredentials += _UserNameHolder.Text; 
        _LoginCredentials += "\n"; 
        _LoginCredentials = "Password: "; 
        _LoginCredentials += _PasswordHolder.Password; 

        //I added this afterwards. Before it was not here. And still it was not working. 
        WritingLoginInfo.Flush(); 
        WritingLoginInfo.Write(_LoginCredentials.ToCharArray(), 0, _LoginCredentials.Length); 
        WritingLoginInfo.Close(); 
        WritingStreamForLoginInfo.Close(); 
       }//End of 1st using clause 
      }//End of second using clause 
     }//End of third using clause 

上面寫的代碼在執行上的功能執行登錄按鈕的點擊事件。 代碼發送此錯誤: 應用商店必須爲此操作打開。

異常細節:

System.ObjectDisposedException了未處理

消息=商店必須打開此操作。

堆棧跟蹤:

at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, IsolatedStorageFile isf) 

    at System.IO.IsolatedStorage.IsolatedStorageFileStream..ctor(String path, FileMode mode, FileAccess access, IsolatedStorageFile isf) 

    at SafeMessenger.MainPage._LoginButton_Tap(Object sender, GestureEventArgs 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, Int32 actualArgsTypeIndex, String eventName) 

現在最後一件事情,我要告訴你的人。在我做之前,爲每件事物創建一個單獨的IsolatedStorageFile對象。這是上面的代碼和目錄創建代碼。那時我得到這個錯誤: 「IsolatedStorage不允許操作」。

現在,我試圖通過各種變量的調試細節,我發現這可能是一些幫助你的人。請記住_GlobalAccessRight是IsolatedStorageFile類型的全局私有變量。

配額 'this._GlobalAccessRight.Quota' 扔類型的異常 'System.ObjectDisposedException' 長{} System.ObjectDisposedException

請幫助我。感謝您的時間和任何幫助,提前。這將是一個很大的幫助。

+0

孤立的存儲是一個疼痛處理!這些錯誤非常含糊。如果你沒有找到一個堅實的答案這個嘗試我的免費DLL EZ_Iso。它可以在一次通話中爲您連續播放所有內容。你可以做自定義對象,甚至圖像。去檢查一下。很容易使用http://anthonyrussell.info/postpage.php?name=47 –

回答

2

因此,經過閱讀和思考了很多,我終於得到了自己的代碼。 首先,由於我對流的處理不當,首先出現操作不允許的錯誤。

首先,我改變了這些行:

. 
. 
. 
} 
else 
    _GlobalAccessRight.CreateFile(_DirectoryForLogin + "\\" + _FileForLogin); 
      //This part basically only creates the file, if directory was already existing. 
} 
else 
    { 
     //Creates directory as well as file. 
     _GlobalAccessRight.CreateDirectory(_DirectoryForLogin); 
     _GlobalAccessRight.CreateFile(_DirectoryForLogin + "\\" + _FileForLogin); 
    } 

要:

. 
. 
. 
} 
else 
    _GlobalAccessRight.CreateFile(_DirectoryForLogin + "\\" + _FileForLogin).Dispose(); 
      //This part basically only creates the file, if directory was already existing. 
} 
else 
    { 
     //Creates directory as well as file. 
     _GlobalAccessRight.CreateDirectory(_DirectoryForLogin); 
     _GlobalAccessRight.CreateFile(_DirectoryForLogin + "\\" + _FileForLogin).Dispose(); 
    } 

第二個錯誤是這樣的:我 全局聲明的IsolatedStorageFile對象。在我的第一個使用區塊中使用後:

using(_GlobalAccessRight){ 
     //Checking if directory exists; case when user had already been logged in. 
     if (_GlobalAccessRight.DirectoryExists(_DirectoryForLogin)) 
     { 

。 。 。 。 它被放置在它的末尾。 因此,當我再次使用它的功能:

using(_GlobalAccessRight){ 
     //I have also tried by giving the FileShare argument below. 
     using(IsolatedStorageFileStream WritingStreamForLoginInfo = new IsolatedStorageFileStream(_DirectoryForLogin + "\\" + _FileForLogin, FileMode.OpenOrCreate, FileAccess.ReadWrite, _GlobalAccessRight)){ 
      using(StreamWriter WritingLoginInfo = new StreamWriter(WritingStreamForLoginInfo)){ 
       String _LoginCredentials = "UserName: "; 

。 。 。 它向我拋出錯誤消息: 「商店必須爲此打開。」

所以我改成了這樣:

using(_GlobalAccessRight = IsolatedStorageFile.GetUserStoreForApplication()){ 
     using(IsolatedStorageFileStream WritingStreamForLoginInfo = new IsolatedStorageFileStream(_DirectoryForLogin + "\\" + _FileForLogin, FileMode.OpenOrCreate, FileAccess.ReadWrite, _GlobalAccessRight)){ 
      using(StreamWriter WritingLoginInfo = new StreamWriter(WritingStreamForLoginInfo)){ 
       String _LoginCredentials = "UserName: "; 

完蛋了!好樣的! :)

+0

一些幫助來自這個問題: http://stackoverflow.com/questions/12584813/operation-not-permitted-on-isolatedstoragefilestream – TriumphTruth

0

嘗試刪除以下兩行:

WritingLoginInfo.Close(); 
WritingStreamForLoginInfo.Close(); 

using塊應該打開和關閉/自動配置流。也許在代碼嘗試關閉using塊末尾的已關閉連接時出現錯誤「Store必須爲此操作打開」。

+0

之後沒有任何改變。 Brother這部分代碼永遠不會運行。這是拋出這個錯誤的第二個使用語句。沒有代碼超出它。 – TriumphTruth

相關問題