944,023 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 2781
  • VB.NET RSS
Jan 17th, 2007
0

urgent!!!!!!!!

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
bhavna_816 is offline Offline
116 posts
since Sep 2006

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Sms system program
Next Thread in VB.NET Forum Timeline: Multithreaded P2P app





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC