Ayush Jha
Ayush Jha

Reputation: 23

IsolatedStorageException was Unhandled:Operation not premitted on IsolatedStorageFileStream

enter image description here

I'm developing a simple app for Windows Phone using SDK 7.1, and I'm getting the error

IsolatedStorageException was Unhandled:Operation not premitted on IsolatedStorageFileStream

within MainPage.xaml.cs

Code Snippet:

private void btnRd_file_Click(object sender, RoutedEventArgs e)

   {

       IsolatedStorageFile ISF = IsolatedStorageFile.GetUserStoreForApplication();

       IsolatedStorageFileStream FS = ISF.OpenFile("pwd1.txt", FileMode.Open, FileAccess.Read);

      using (StreamReader SR = new StreamReader(FS))

while trying to Run the application on Windows Phone Emulator.

Upvotes: 0

Views: 419

Answers (3)

A.G
A.G

Reputation: 1

Just put the codes for which it is giving the exception in the try catch block

eg.

try {
  ..your code..
}
catch { ... code to handle exception ... }

The above changes will handle all the possible exception.

Upvotes: 0

SandyNegi.037
SandyNegi.037

Reputation: 178

There can be more than one issue due to which this type of error occurs. In ur case u are opening the file in read mode which means file must exist at the given path before executing

IsolatedStorageFileStream FS = ISF.OpenFile("pwd1.txt", FileMode.Open, FileAccess.Read);

line of code.

And if file is exists at given path and u still facing this error. Than see whether u have opened this file before somewhere in code and forget to close the stream using dispose or using statement.

This type of problem also occurs when u already opened the file with and forget to close/dispose it.

Note: IsolatedStorageFileStream doesn't provide the exact/helpful information about the original core of error, so developer must debug and see values of variables and objects to get the core of issue.

Upvotes: 0

Jon
Jon

Reputation: 2891

You will get this error if the file does not exist. You should check to see if it exists first.

Upvotes: 0

Related Questions