none
ApplyPolicy returns HRESULT: 0x80070005 (E_ACCESSDENIED) RRS feed

  • Question

  • Hey guys

    I’m currently working on a VSTO-project which amongst other things applies (or at least tries to :-) ) a MS RMS Template to a Word-Document via the Permissions.ApplyPolicy-Method. I currently call this method from the before-save event.

    The first time I call this method, everything is fine, the document is protected and no exception is fired. When I now try to set another template on the file, I get a System.UnauthorizedAccessException with HRESULT: 0x80070005 (E_ACCESSDENIED).

    If I manually remove the old template, I get no exception. Nevertheless when I try to remove the template with the Permissions.RemoveAll() method, I still cannot update the template.

    Hopefully you can help me

    Thanks

    EDIT: Forget to tell: Add-In is developed with VS 2015 and target solution is Word 2013


    • Edited by tburandt Wednesday, April 6, 2016 12:55 PM
    Wednesday, April 6, 2016 12:52 PM

All replies

  • Hello,

    What code exactly do you have now?  What method fires the exception mentioned in the post?


    [custom.development]

    Wednesday, April 6, 2016 2:24 PM
  • Hi tburandt,

    >> When I now try to set another template on the file

    What do you mean setting another template? Do you mean you want to apply multiple policy to the same document? If you remove all UserPermission objects before you apply new policy, will you get this error?

    >> Nevertheless when I try to remove the template with the Permissions.RemoveAll() method, I still cannot update the template.

    Which code you used to remove permission? It would be helpful if you could share us your code, and MS RMS template.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Thursday, April 7, 2016 6:21 AM
  • Hey Edward and Eugene,

    >> What do you mean setting another template? Do you mean you want to apply multiple policy to the same document? If you remove all UserPermission objects before you apply new policy, will you get this error?

    I want to remove the current AD RMS-template and set another on the document. E.g. I have two templates from our AD RMS, one for "confidential" documents (confidential.xml) and one for "secret" documents (secret.xml). I decide to have a confidential document and set the template to confidential.xml (works fine). Now on the next save I will change the template to secret.xml, because I think it has some more-severe information in it. Then, in the before save event of the word-application I call a code like this:

    public void UpdateTemplate(Document document, string templateFile)
    {
        var permission = document.Permission;
        if( permission == null)
            return;
    
        if (permission.PermissionFromPolicy)
            permission.RemoveAll();
    
        permission.ApplyPolicy(templateFile); // Here the exception is fired
    }

    When a document has the template confidential.xml and i call this Method to set the template secret.xml i get the exception on the last line.

    >> Which code you used to remove permission? It would be helpful if you could share us your code, and MS RMS template.

    Unfortunately I’m not allowed to append the template due to company rules.

    Thanks

    Thursday, April 7, 2016 1:49 PM
  • Hi tburandt,

    To be honesty, I am not familiar with MS RMS template, I failed to create such a file.

    For your issue, I suggest you comment out “permission.ApplyPolicy(templateFile);”, after you run “permission.RemoveAll();”, I suggest you whether the permission has been removed successfully. If they are removed, I suggest you run this “permission.ApplyPolicy(templateFile);” again on this file to check whether this error still exist.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, April 8, 2016 8:15 AM