locked
System.UnauthorizedAccessException (E_ACCESSDENIED) when deleting multiple files from ApplicationStorage

    Question

  • Hi,

    I'm currently building a windows store app with C#. Inside that app I manage some elements which have normally two files, one content file and one thumbnail file (for easier databinding)
    Currently only the thumbnail is used as I'm not yet ready for the other part (I'm just testing some things atm).

    However, when I try to delete one item only, it works. If I select multiple items at one time and try to delete them, I always get a System.UnauthorizedAccessException when the part begins where the file are actually deleted.

    The strange thing is, when I create new files and delete them, it works, I only get this error when the file (in this case the thumbnail) was actually used (I show the thumbnails in a gridView as Image element)

    Can anyone tell me why I cannot delete those files? I tried many ways to delete them, I also removed the files from UI first, then waited 60s (with Task.Delay) and then tried to remove the files, still no success.
    Could it be that the Image element is still holding an reference to that file it has as its Source property before even though it was removed from the UI first?

    If possible please help me as I'm clueless what to do. The files I manage are somehow private to my future users so I want them deleted asap after the user says they should get deleted and not only when for example the app is restarted.

    Any help will be greatly appreciated.

    Best regards,

    internetfreak

    Thursday, January 30, 2014 9:06 PM

Answers

  • After fiddling around some time I finally found the answer. Thanks to Prashant it was clear that the UI requeried my images multiple times so it hat at least one handle open to the file. Strangely this was no problem when I deleted only one folder, it only happened at 2 or more folders.

    Anyway, I now changed the way I handle the images for display and it works. Basically, I still reference an Uri to the files because it's more memory friendly but when I load the folders I also set up an BitmapImage per folder where I give the Uri as parameter to the constructor. When I delete the folder I first set the BitmapImage to null so the handle could get released and I'm able to do what I want to do with the file (in this case I want to delete it but in a different place of my app I also replace it when necessary)

    Much thanks to prashant for helping me, I don't know if I had found the problem without him.

    Monday, February 17, 2014 8:58 PM

All replies

  • Can you share a repro of your problem via SkyDrive? It will be easier to understand your scenario if you share code.

    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Friday, January 31, 2014 1:19 AM
    Moderator
  • Here are the tow relevant files containing all the necessary code. I removed all unneeded codeparts to maintain the viewability and also to reduce confusion.

    I hope you can see the issue. If you need more code or the complete application, please contact me directly because I don't want to share my complete project in the public as it contains all necessary informations which should keep my users files safe (It's an app which protects the photos which the user adds so only he can access it)

    FolderManager.cs
    http://sdrv.ms/1gwfKWF

    OverviewPage.cs
    http://sdrv.ms/1gwg4Vi

    Ad said, the OverviewPage shows the elements (named folder) in a grouped gridview with their thumbnail (stored as string containing an "ms-appdata:///" uri) which is diretly bound to the UI over dataBinding


    Friday, January 31, 2014 7:34 AM
  • So which line do you see the UnAuthorizedException error? Is it on the folderContentFile.DeleteAsync() or folderThumbnail.DeleteAsync()?

    How can I contact you directly? Do you have an email address that you can share?


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Saturday, February 01, 2014 12:53 AM
    Moderator
  • As the ContentFile is currently not in use I only get the Exception when deleting the Thumbnail.

    The content file is only used rarely, all I do is read it and do my actions with it so it gets not shown in any UI and thus I should not get an exception when it's implemented later in the development.

    For contacting me, you can use this address: internetfreak1 [at] live. de

    I hope we can get that problem fixed somehow as it's rather annyoing and stops me in my development process

    Saturday, February 01, 2014 11:19 AM
  • Anyone else who could help me? I want to get my app published soon but first I need to clear all blocker which keep me away from progressing.

    Any help is greatly appreciated

    Monday, February 03, 2014 2:43 PM
  • After fiddling around some time I finally found the answer. Thanks to Prashant it was clear that the UI requeried my images multiple times so it hat at least one handle open to the file. Strangely this was no problem when I deleted only one folder, it only happened at 2 or more folders.

    Anyway, I now changed the way I handle the images for display and it works. Basically, I still reference an Uri to the files because it's more memory friendly but when I load the folders I also set up an BitmapImage per folder where I give the Uri as parameter to the constructor. When I delete the folder I first set the BitmapImage to null so the handle could get released and I'm able to do what I want to do with the file (in this case I want to delete it but in a different place of my app I also replace it when necessary)

    Much thanks to prashant for helping me, I don't know if I had found the problem without him.

    Monday, February 17, 2014 8:58 PM
  • Glad to see that you have a solution now!

    Thanks,

    Prashant.


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Monday, February 17, 2014 9:30 PM
    Moderator