I wrote a code in
VB.NET which accesses the outlook folders.Following is the code.According to this code it displays outlook folders and there is hyperlink on each subject.I want when we click on the subject the message body should be
dispalyed.in href how can we do this? I know we have to write a function to dispalay the body.but i don't know how to do this?can u please tell me ?
an exception Invalid cast exception is coming in this line
oMsg = oItems.Item(i)
it means when we access the folders and suppose the folder contains a calender meeting items i.e. another cast or datatype then the inner loop stops executing.
please tell me to handle this exception?
code is like this
we ahve to add a refernce Microsoft outlook 11.0 library from Project->add reference -> COM tab and the code is this please help me?
Imports System.Runtime.InteropServices
Imports
Microsoft.Office.Interop.Outlook
Imports
System.IO
Module
Module1
Sub Main()
'OlSecurityManager.DisableOOMWarnings = True
Try
' Create Outlook application.
Dim app
As Microsoft.Office.Interop.Outlook.Application =
New Microsoft.Office.Interop.Outlook.Application
' Get NameSpace and Logon.
Dim appNameSpace
As Microsoft.Office.Interop.Outlook.NameSpace = app.GetNamespace("MAPI")
appNameSpace.Logon("Outlook", "bhavna123",
False,
True)
' Get Messages collection of Inbox.
Dim fs
As New FileStream("c:\Outlook_Folders.htm", FileMode.Create, FileAccess.Write)
Dim s
As New StreamWriter(fs)
Dim oPFolder
As Microsoft.Office.Interop.Outlook.MAPIFolder = appNameSpace.Folders.GetFirst()
Dim oFol
As Microsoft.Office.Interop.Outlook.Folders = oPFolder.Folders
Dim sfolder
As Microsoft.Office.Interop.Outlook.MAPIFolder
Dim j
As Integer
For j = 1
To oFol.Count
sfolder = oFol.Item(j)
s.WriteLine("<li>")
s.WriteLine(sfolder.Name)
s.WriteLine("</li>")
s.WriteLine("<ul>")
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.exe?Personal Folders&Inbox&oMsg=i>" + oMsg.Subject + "</a>")
s.WriteLine("</li>")
Catch ex
As InvalidCastException
Console.WriteLine("Caught:InvalidCastException", ex)
'Ignore any invalid casts.
End Try
Next
s.WriteLine("</ul>")
s.WriteLine("</ul>")
Next
s.Close()
fs =
New FileStream("c:\Outlook_Folders.htm", FileMode.Open, FileAccess.Read)
Dim d
As New StreamReader(fs)
d.BaseStream.Seek(0, SeekOrigin.Begin)
'LogOff
appNameSpace.Logoff()
'cleanup
app =
Nothing
appNameSpace =
Nothing
'oItems = Nothing
Console.ReadLine()
Catch exc
As ApplicationException
Console.WriteLine("Caught:ApplicationException", exc)
'Finally
' OlSecurityManager.DisableOOMWarnings = False
End Try
End Sub
End
Module