bhavna_816 0 Junior Poster

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.