| | |
urgent!!!!!!!!
Please support our VB.NET advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Sep 2006
Posts: 116
Reputation:
Solved Threads: 0
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
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
- pls heeeeeeeeelp its urgent. (C)
- Urgent! (C++)
- URGENT: Need help on I/O code! (Java)
- Urgent help (Networking Hardware Configuration)
- Homepage keeps switching back to a porn site (Web Browsers)
- Importing SQL Script File - Urgent !! (Database Design)
Other Threads in the VB.NET Forum
- Previous Thread: Sms system program
- Next Thread: Multithreaded P2P app
Views: 2264 | Replies: 0
| Thread Tools | Search this Thread |
Tag cloud for VB.NET
.net .net2005 30minutes 2005 2008 access application arithmetic array basic binary bing button buttons c# center check code combobox component connectionstring convert crystalreport data database databasesearch datagrid datagridview design designer dissertation dissertations dissertationthesis dll dropdownlist error excel file-dialog folder ftp google hardcopy highlighting image images inline installer listview login math mobile ms net networking opacity output peertopeervideostreaming picturebox picturebox1 plugin port print printing problem problemwithinstallation project reports" save savedialog searchbox serial server soap sorting sql string studio syntax tcp text textbox timer toolbox trim updown upload usercontrol vb vb.net vb.netcode vb2008 vbnet view visual visualbasic visualbasic.net visualstudio visualstudio2008 web wpf





