I am writing a code in VB.NET to access MS Outlook folders.Its giving all the folders and their msgs but when any calender meeting or any other things other than the mails appears any the folders like deleted items ,Inbox etc. then it shows exception in line
oMsg = oItems.Item(i)
in the following code.
and the loop stops executing.What is the solution for tht?
Dim oItems As Microsoft.Office.Interop.Outlook.Items = sfolder.Items
Dim oMsg As Microsoft.Office.Interop.Outlook.MailItem
Dim i As Integer
For i = 1 To oItems.Count
Try
oMsg = oItems.Item(i)
s.WriteLine("<li>")
s.WriteLine("<a href=ConsoleApplication1.vb?oPFolder=Personal Folders&sFolder=Inbox&oMsg=i>" + oMsg.Subject + "</a>")
s.WriteLine("</li>")
Catch ex As InvalidCastException
Console.WriteLine("Caught:InvalidCastException", ex)
End Try