locked
Is there anyway to lock the folder ? RRS feed

  • Question

  • Hi I am working in outlook addins project where i can extract attachment from the mail items. I am extracting my attachment on particular folder like C:\Attachments. Now if i wish to lock this folder until my process is completed how can i do? Right now, during extracting attachments on folder C:\Attachments I can delete the folder 'Attachment' from outside. I want to lock that folder until my process is completed. How can i achieve that?

     

    Sunday, March 27, 2011 11:46 AM

Answers

All replies

  • You cannot do that.
    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Monday, March 28, 2011 8:48 PM
  • Hi,

    I see it's already quite old thread, however I'm trying to solve similar problem and my idea is to handle folder "move" events (http://msdn.microsoft.com/en-us/library/microsoft.office.interop.outlook.mapifolderevents_12_event_members.aspx) and if I was in the folder processing, I'd cancel them.

    What do you think about this idea? 

    I'm going to try it now, so I'll let you know about the result.

     

    Filip

    Thursday, August 4, 2011 3:20 PM
  • That event is not reliable, plus you would not be able to prevent the items in the fodler from being modified or deleted.
    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Thursday, August 4, 2011 6:42 PM
  • Hi Dmitry,

    yes, I had  problems with these events, however it was solved by the 12/2010 hotfix  (http://support.microsoft.com/kb/2459115 - I found this information somewhere in this forum). At least at this moment I have a feeling that it fires these events normally. I tried my approach and it seems that it works. When I run my folder processing, I set the variable "working" and when one of those events if fired I just check if the "working is true". In this case I display MessageBox and set the event parameter Cancel to true. And nothing is deleted. Works with both folders and items. But this was just a test, you have probably more experience with it and maybe I will face some other problem later...

     

    Best regards

     

    Filip


    Friday, August 5, 2011 7:42 AM
  • ... but one problem of my approach has appeared:

     

    I'm using this in the Add-In which synchronizes emails with Sharepoint and the problem is if some folder was deleted in SP, then I need to delete it also in Outlook, however I locked it by the "beforeMove event handling" and I'm not able to recognize in the event what is the origin of the request for movement (or deletion of course), so then I cancel also this (needed) functionality.

    ...such a simple thing and so complicated...

     

    any idea welcome ! ;-)

     

    F.


    Saturday, August 6, 2011 3:29 PM
  • Use a global a variable as a flag when the folder should/should not be deleted.

    You can reset it before deleting the folder, then restore it.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Saturday, August 6, 2011 4:44 PM
  • Yes, I just have done it... I switch off the protection just for the moment when I'm deleting it by the code. Don't know if could happen that user would delete the folder at exaclty the same time... But the chances are low (I hope)

     

    F.

    Saturday, August 6, 2011 5:31 PM