1

我希望枚举用户在收件箱中收到的任务请求。我认为我有正确的方法,查看收件箱文件夹,然后检查邮件类等于 IPM.taskrequest 的位置,但现在可以了。这是我的代码,任何建议将不胜感激,谢谢!

Private Sub GetTaskRequests(objApp As Microsoft.Office.Interop.Outlook.Application)
        Dim objNS As Outlook.NameSpace = objApp.GetNamespace("MAPI")
        Dim folder As Outlook.MAPIFolder = _
            objNS.GetDefaultFolder( _
            Outlook.OlDefaultFolders.olFolderInbox)

        Dim searchCriteria As String = "[MessageClass] = 'IPM.TaskRequest'"
        Dim strBuilder As StringBuilder = Nothing
        Dim counter As Integer = 0
        Dim taskItem As Outlook._TaskRequestItem = Nothing
        Dim folderItems As Outlook.Items = Nothing
        Dim resultItem As Object = Nothing
        Dim TTDcounter As Integer = 0
        Try
            folderItems = folder.Items
            folderItems.IncludeRecurrences = True
            If (folderItems.Count > 0) Then
                resultItem = folderItems.Find(searchCriteria)
                If Not IsNothing(resultItem) Then
                    strBuilder = New StringBuilder()
                    Do
                        If (TypeOf (resultItem) Is Outlook._TaskRequestItem) Then
                            counter += 1
                            taskItem = resultItem
                            If Not (taskItem.Status = Outlook.OlTaskStatus.olTaskComplete) Then
                                strBuilder.AppendLine("#" + counter.ToString() + _
                                " Subject: " + taskItem.Subject + _
                                " Percent Complete: " + taskItem.PercentComplete.ToString() + _
                                " Body: " + taskItem.DueDate)

                                If taskItem.Categories = "TTD" Then
                                    TTDcounter += 1
                                    Dim listarray() As String = {taskItem.Delegator, taskItem.Subject, taskItem.DueDate, stripEstComp(taskItem.Body.ToString())}
                                    taskPaneControl3.ListView1.Items.Add(TTDcounter).SubItems.AddRange(listarray)
                                End If

                            End If
                        End If
                        Marshal.ReleaseComObject(resultItem)
                        resultItem = folderItems.FindNext()
                    Loop Until IsNothing(resultItem)
                End If
            End If
            If Not IsNothing(strBuilder) Then
                Debug.WriteLine(strBuilder.ToString())
            Else
                Debug.WriteLine("There is no match in the " + _
                                   folder.Name + " folder.")
            End If
        Catch ex As Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        Finally
            If Not IsNothing(folderItems) Then Marshal.ReleaseComObject(folderItems)
        End Try
    End Sub
4

0 回答 0