VB.NET, App - How can i close an Outlook Item?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chrisli
    New Member
    • Nov 2008
    • 11

    VB.NET, App - How can i close an Outlook Item?

    Hey,
    i have written this code to read all Outlook Appointments from another user and fill them into my DGV.

    Code:
    Public Sub ReadOtherUserAppointment(ByVal UserName As String)
            Dim objolApp As New Outlook.Application
            Dim objNS As Outlook.NameSpace
            Dim objRecip As Outlook.Recipient
            Dim objFolder As Outlook.MAPIFolder
            objNS = objolApp.GetNamespace("MAPI")
            objRecip = objNS.CreateRecipient(UserName)
            objRecip.Resolve()
            Dim i As Integer = 0
    
                If objRecip.Resolved Then
                    objFolder = objNS.GetSharedDefaultFolder(objRecip, Outlook.OlDefaultFolders.olFolderCalendar)
    
                    For x As Integer = 1 To objFolder.Items.Count
                            If objFolder.Items.Item(x).categories = "Urlaub" Then
                            dgv.Rows.Add()
                            dgv.Item("clmstart", i).Value = objFolder.Items.Item(x).start
                            dgv.Item("clmend", i).Value = objFolder.Items.Item(x).end
                            dgv.Item("clmsubject", i).Value = objFolder.Items.Item(x).subject
                            dgv.Item("clmcategory", i).Value = objFolder.Items.Item(x).categories
                            i = i + 1
                        End If
    objFolder.Items.Item(x).Close(Outlook.OlInspectorClose.olDiscard)                   
     Next
    
                End If
    Now when i read the appointments and fill them into my DataGridView there is an Error after some items:
    System.Runtime. InteropServices .COMException (0x80040305): Your server administrator has limited the number of items you can open simultaneously. ..

    I tried objFolder.Items .Item(x).Close( Outlook.OlInspe ctorClose.olDis card), but this gievs me the error:
    System.Runtime. InteropServices .COMException (0x8002000F) Parameter not optional...

    Any ideas?

    Greetings
  • chrisli
    New Member
    • Nov 2008
    • 11

    #2
    I found a solution :)

    After i went through every Item i do this:

    Code:
    If objRecip.Resolved Then
    objFolder = objNS.GetSharedDefaultFolder(objRecip, Outlook.OlDefaultFolders.olFolderCalendar)
    
    For x As Integer = 1 To objFolder.Items.Count
    
    'Same code as above...
    
    End If            
    
    'Quit the Session when every item is added.
            
    objolApp.Quit()
    
    'Run garbagecollector
    
    GC.Collect()
    GC.WaitForPendingFinalizers()
    GC.Collect()
    GC.WaitForPendingFinalizers()
    Next
    End If
    Simple, huh? :)

    Sorry for my bad english.

    Greetings from Germany. :)

    Comment

    Working...