none
-2147352567 Cannot move the items RRS feed

  • Question

  • I have a VB.Net application that automates Outlook using Interop. One function of the application is to move an Outlook message to a subfolder of a shared inbox when the message has been processed, using MailItem.Move(Folder). About 50% of the time, the move of the message fails with error -2147352567 returned. Is there any way of determining why this is happening?

    Thanks in advance.

    Monday, March 9, 2015 4:01 PM

Answers

All replies

  • Hello Tony,

    What code do you use for processing the items in Outlook? When and where do you run it?

    Monday, March 9, 2015 4:22 PM
  • Hi Eugene,

    I'll paste the relevant code below. It's run on the user's PC in a VB.Net 2010 application.

        Public Sub ArchiveCompletedMessage(ByRef pstrMessageID As String)
    
            Dim objOutlook As Object = New Outlook.Application
            If IsNothing(objOutlook) Then
                MsgBox("Error: An attempt to access or start Outlook has failed. Please contact the Help Desk.", MsgBoxStyle.Exclamation, gstrAppName)
                Exit Sub
            End If
    
            Dim objNameSpace As Object = objOutlook.GetNamespace("MAPI")
            If IsNothing(objNameSpace) Then
                MsgBox("Error: An attempt to access the Outlook Namespace has failed. Please contact the Help Desk.", MsgBoxStyle.Exclamation, gstrAppName)
                objOutlook = Nothing
                Exit Sub
            End If
    
            Dim objMessage As Outlook.MailItem = objNameSpace.GetItemFromID(pstrMessageID)
    
            Dim astrFolders() As String = Split(gstrDeptMailboxActioned, "\")
            Dim intCount As Integer = 0
            If currentSettings.IsDebugMode = True Then
                MsgBox("Move e-mail: step 1")
            End If
            On Error Resume Next
            Dim objFolder As Object = objNameSpace.Folders(astrFolders(0))
            If Err.Number <> 0 Then
                MsgBox("An error has occurred when trying to access the departmental processed mailbox '" & astrFolders(0) & "'." & vbNewLine & vbNewLine & Err.Number & " - " & Err.Description, MsgBoxStyle.Exclamation, gstrAppName)
                On Error GoTo 0
                Exit Sub
            End If
            On Error GoTo 0
            If currentSettings.IsDebugMode = True Then
                MsgBox("Move e-mail: step 2")
            End If
            Dim objFinalFolder As Outlook.Folder = objFolder
            Dim bolFolderFound As Boolean = False
            For intCount = 1 To astrFolders.GetUpperBound(0)
                For Each objSubFolder As Outlook.Folder In objFinalFolder.Folders
                    If objSubFolder.Name = "Inbox" Then
                        objFolder = objSubFolder
                    End If
                    If objSubFolder.Name = astrFolders(intCount) Then
                        objFinalFolder = objSubFolder
                        bolFolderFound = True
                        Exit For
                    Else
                        bolFolderFound = False
                    End If
                Next
            Next
            If bolFolderFound = False Then
                MsgBox(" An atempt to access folder " & gstrDeptMailboxActioned & " has failed. The current e-mail will not be marked as read or moved to the actioned folder.", MsgBoxStyle.Information, gstrAppName)
                objNameSpace = Nothing
                objOutlook = Nothing
                Exit Sub
            End If
    
            If objMessage.UnRead Then
                objMessage.UnRead = False
            End If
            On Error Resume Next
            objMessage.Move(objFinalFolder)
            If Err.Number <> 0 Then
                MsgBox("An error occurred when trying to move the e-mail to the actioned folder. The error message follows:" & vbNewLine & vbNewLine & "[" & Err.Number & "] - " & Err.Description & vbNewLine & vbNewLine & "Please move the message manually.", MsgBoxStyle.Exclamation, gstrAppName)
                objMessage = Nothing
                On Error GoTo 0
                Exit Sub
            End If
            On Error GoTo 0
    
            Dim objTmpMessage As Outlook.MailItem
            For Each objTmpMessage In objFolder.Items
                If objTmpMessage.EntryID = pstrMessageID Then
                    MsgBox("The e-mail you have just processed was not moved into the actioned folder; please move the message manually to avoid case duplication.", MsgBoxStyle.Information, gstrAppName)
                    Exit Sub
                End If
            Next
    
        End Sub
    


    Monday, March 9, 2015 4:27 PM
  • When and where is the application run?

    Try to use the GetSharedDefaultFolder method of the NameSapce to get a Folder object that represents the specified default folder for the specified user.

    Monday, March 9, 2015 4:35 PM
  • Eugene,

    The application is run by the users at their PCs. Typically it would be open all day long and used occasionally as needed.

    The folder in question isn't any sort of default folder; it's a shared, departmental Inbox. The problem is not when the folder is selected, it is when the move is actually requested.

    Regards,

    Tony.

    Monday, March 9, 2015 4:41 PM
  • Tony,

    The GetSharedDefaultFolder method of the NameSapce is used to get a shared Folder object.

    Also I'd recommend releasing all underlying COM objects instantly. Use System.Runtime.InteropServices.Marshal.ReleaseComObject to release an Outlook object when you have finished using it. Then set a variable to Nothing in Visual Basic (null in C#) to release the reference to the object. You can read more about that in the Systematically Releasing Objects article.

    Monday, March 9, 2015 4:46 PM
  • Eugene,

    As I understand it, the GetSharedDefaultFolder takes two arguments; a recipient (say, me) and a constant that identifies the folder to be returned (default Inbox, default Calendar etc. etc.). So, if I was to pass myself as the recipient and the constant for default Inbox, it would return the inbox found in the following location: "Spratt, Tony\Inbox", whereas the folder I actually want to open is "London Underwriting\Inbox\Actioned" which is no-one's default folder.

    Thanks for the advice re: ReleaseComObject - I'll look into it. How does that work where the COM object exists within a loop at the top level, e.g.

    For Each objMailItem As New Outlook.MailItem In objFolder.MailItems
      'do something
    Next

    In that situation will there be anything to release after the For...Next loop completes?

    Monday, March 9, 2015 5:02 PM
  • Tony,

    Yes, the method takes two arguments. The recipient should be the owner, not you.

    Use the for loop instead of foreach. Thus, you will be able to release each object in the loop.

    Monday, March 9, 2015 5:06 PM
  • Eugene,

    I will look at the departmental mailbox and see if I can determine its owner and see if that makes any difference.

    Thanks,

    Tony.

    Monday, March 9, 2015 5:09 PM
  • Refactor the code to release all underlying COM objects instantly. It may help also.
    Monday, March 9, 2015 5:11 PM