PC Review


Reply
Thread Tools Rate Thread

COMException: "Can't move the items." on MailItem.Move

 
 
Jim Carpenter
Guest
Posts: n/a
 
      19th Dec 2003
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
 
Reply With Quote
 
 
 
 
Dmitry Streblechenko
Guest
Posts: n/a
 
      19th Dec 2003
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



 
Reply With Quote
 
Jim Carpenter
Guest
Posts: n/a
 
      19th Dec 2003
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

 
Reply With Quote
 
Dmitry Streblechenko
Guest
Posts: n/a
 
      19th Dec 2003
Hmmm... I don't recognize that error code. Where does item come form? How
long to you keep it referenced? It could be that your code is locking it:
after a message is moved, it is gone, so you must dereference it as soon as
possible.

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)...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
listbox "move to back" or "move forward" position MechEngr Microsoft Access Forms 9 21st Feb 2009 10:29 PM
How do I move a document from "recent items" to "documents" John Gerke in Central Oregon Microsoft Excel New Users 1 2nd Mar 2008 08:31 AM
"Can't move the item" msg trying to move results of "Find" in Outl =?Utf-8?B?WWFtYnU=?= Microsoft Outlook Discussion 1 25th Sep 2004 09:09 PM
Error: "Can't move the items" OL 2002; but can del and move kiln Microsoft Outlook Discussion 0 15th Aug 2004 01:22 AM
How to move "Junk E-mail" to "Deleted Items" folder automatically? pwalker Microsoft Outlook 2 8th Nov 2003 06:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:39 PM.