PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook Program Addins
COMException: "Can't move the items." on MailItem.Move
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook Program Addins
COMException: "Can't move the items." on MailItem.Move
![]() |
COMException: "Can't move the items." on MailItem.Move |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
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 |
|
|
|
#2 |
|
Guest
Posts: n/a
|
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" <jamescarpenter@hotmail.com> wrote in message news:6138e84f.0312181832.62ecf8a2@posting.google.com... > 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 |
|
|
|
#3 |
|
Guest
Posts: n/a
|
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" <dmitry@dimastr.com> wrote in message news:<O6v5aFexDHA.2712@tk2msftngp13.phx.gbl>... > 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" <jamescarpenter@hotmail.com> wrote in message > news:6138e84f.0312181832.62ecf8a2@posting.google.com... > > 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 |
|
|
|
#4 |
|
Guest
Posts: n/a
|
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" <jamescarpenter@hotmail.com> wrote in message news:6138e84f.0312191147.4181f343@posting.google.com... > 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" <dmitry@dimastr.com> wrote in message news:<O6v5aFexDHA.2712@tk2msftngp13.phx.gbl>... > > 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" <jamescarpenter@hotmail.com> wrote in message > > news:6138e84f.0312181832.62ecf8a2@posting.google.com... > > > 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 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

