Dmitry,
Thanks for your response. I don't think that I can safely ignore
the exception because it is failing to move the email. I ran the code
in the debugger and got some more detail on the exception:
Exception: System.Runtime.InteropServices.COMException (0xC6220009):
Can't move the items.
ErrorCode = -970850295
HelpLink =
InnerException =
Message = Can't move the items.
Source = Microsoft Outlook
TargetSite = System.Object
Move(Microsoft.Office.Interop.Outlook.MAPIFolder)
I did a search on MSDN and Usenet but couldn't find anything for the
HRESULT = -970850295. Is there some source that lists all possible
Outlook ErrorCodes/HRESULTs?
I think that the .NET equivalent of IDispatch.Invoke() would be to use
the classes of the System.Reflection namespace, but I am not sure how
this would help me here. It seems like I am able to programmatically
move EmailItems to different folders, but as soon as I open/move them
in the GUI, the code stops working. Is there anyway to see if some
other process/thread has locked the item? Is there some other API
that I should/could be using (e.g. MAPI vs. OOM)?
Thanks,
Jim Capenter
SRI International
"Dmitry Streblechenko" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> That error is by design - it is > 0, meaning it is a non-critical error and
> can be safely ignored. .Net runtime (Delphi does that too) expects S_OK (=
> 0) and raises an exception if it is anything else. The only workaround is to
> explicitly call IDispatch.GetIDsOfNames("Move", ...) and IDispatch.Invoke()
> handling any returned errors in your code. Easy to do in C++/Delphi, but I
> have no idea how you would do that in C#.
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy - Outlook, CDO
> and MAPI Developer Tool
>
>
> "Jim Carpenter" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > I am writing a COM Add-In for Outlook 2002 using C#:
> >
> > try
> > {
> > Outlook.NameSpace ns = applicationObject.GetNamespace("MAPI");
> > Outlook.MAPIFolder inbox =
> > ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
> > Outlook.MAPIFolder deleted =
> > ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderDeletedItems);
> > Outlook.MailItem item = (Outlook.MailItem) inbox.Items[0];
> > item = item.Move(deleted);
> > }
> > catch (Exception e)
> > {
> > Debug.WriteLine("Exception: " + e.Message);
> > }
> >
> > When I try and move an item from the Inbox to the Deleted Items
> > folder, the code works correctly. If I then move the item from the
> > Deleted Items folder back to the Inbox using the GUI and run the code
> > again, it fails with a COMException: "Can't move the items." on
> > MailItem.Move.
> >
> > It seems like the GUI is locking the MailItem and preventing the
> > Add-In from accessing it.
> >
> > Any help would be greatly appreciated?
> >
> > Thanks,
> >
> > Jim Carpenter
> > SRI International