Arctic
Arctic

Reputation: 827

Deleting image displayed in Windows Phone Image Control

I have the following code to display image in an Image control.

var stream = isolatedStorage.OpenFile(imageName, System.IO.FileMode.Open, System.IO.FileAccess.Read);
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.SetSource(stream);
imageControl.Source = bitmapImage;

I also want to give the user option to delete the image. I have the following code for it.

myImage.Source = null;
isolatedStorage.DeleteFile(imageName);

But this results in IsolatedStorageException with the message 'Unable to delete the file'.

I can't use stream source property of the bitmap or use Cache option, since Windows phone doesn't support them.

Any other workaround?

Upvotes: 0

Views: 199

Answers (1)

Microsoft DN
Microsoft DN

Reputation: 10020

May be you need to close the fileStream before deleting the file.

Try

stream.Close()

or something like this before deleting the file

OR

If your isolatedStorage variable is of type IsolatedStorageFile then you can directly use

isolatedStorage.DeleteFile("yourfilename.ext");

Upvotes: 1

Related Questions