Move to Folder and Copy Event

  • Thread starter Thread starter A Yadav
  • Start date Start date
A

A Yadav

I am using outlook 2003 and Microsoft.Office.Interop.Outlook. I am using
PostItem to post to a custom folder. I want to prevent all event for these
PostItems (copy, forward, delete, Move etc). Is there a way to handle "Move
to Folder .." and "Copy" events for Folders or PostItem.

Thanks in advance
Abba
 
Each MAPIFolder has an Items collection that has an ItemAdd event you can
handle. It will fire when any item is added to the folder. You'd have to
decide in that event handler whether to allow the item in the folder.
 
The overhead is unavoidable. If you want to monitor more than one folder's
events what I would do is set up a class that handles events for the
folder's Items collection and add a class for each monitored folder to a
collection to allow the references to stay alive and to handle each Items
collection's events discretely.

You can always choose not to handle a specific even such as Remove, but
that's up to you. For copy/move you'd have to handle at least 2 (Remove,
Add). Of course Remove is less than useful since you don't get told what was
removed and it fires after the removal occurs.

For Add you can delete the item if you don't want it added. There are no
Cancel arguments passed in to just disallow the actions.
 
Dont you think it would be an overhead to monitor all folders for ItemsAdd
event? Is this the only way to handle copy and forward events? Any way to
disable the events for a specific folder ?

thanks

Abba
 
Many thanks Ken. I think I will have to do it the hard way and monitor all
the folders for ItemsAdd event. On a different topic, Is there a way to
handle the "Send/Receive" event when the users clicks the "Send/Receive"
button on the outlook toolbar in outlook 2003. Seems like "Send/Receive" is
a CommandBarPopup. I can handle the "Send/Receive All" Event under the
"Send/Receive" dropdown or combobox. Any ideas on handling "Send/Receive"
events ?
 
You can handle the Application object's Send event and also handle the
ItemAdd event for the Inbox folder's Items collection.
 
Well that sounds like a way around. But I have a requirement to update a
custom folder when the user clicks "Send/Receive" button the toolbar in
outlook 2003. When the user clicks the button, my addin will make a
webservice call to fetch some tasks. This tasks are then populated in my
custom folder. Any way we can handled the "Send/Receive" button click event.
The send/receive is a CommandBarPopup object
 
You could try declaring a CommandBarButton object to handle events for that
built-in button and see if that works. You would get the original button and
assign it to your own. If that didn't work you'd have to fall back to
handling the application events, which wouldn't fire if nothing was being
sent or received.

That button Click event wouldn't fire however for automatic send/receives.
 
Can you provide a snippet of code to get the Original commandbarpopup button
as commandbarbutton? Also how would I handle application Events?

Thanks
Abbs
 
You can use OutlookSpy to get the ID properties for Outlook's buttons and
menu items, or there's a list of ID's at www.outlookcode.com. You would then
set your own CommandBarButton object to that ID. In VB/VBA you'd declare a
button object WithEvents and then do the assignment.

You'd use the CommandBarControls collection and its Add method with the Id
argument, then make the newly added CommandBarControl invisible. Since it
shared the same Id as the original button you should get a click for your
button when the original one was clicked. I'm not positive this will work
however, since I've never tried it and I have no idea which of the button
click events would fire first.
 
Back
Top