Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
|
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2009, 11:28 PM
Registered User
 
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default AppointmentItem MAPI showing Specified type cast error

Module Module1
Public MeetingRequestType As String = "IPM.Schedule.Meeting.Request"
Public AppointmentType As String = "IPM.Appointment"
Public MessageType As String = "IPM.Note"
Public TasksType As String = "IPM.Tasks"
Public TaskRequestType As String = "IPM.TaskRequest"
Public StickyNoteType As String = "IPM.StickyNote"
Sub Main()
Dim oSession As MAPI.Session
Dim oCalendar As MAPI.Folder
Dim oAppt As MAPI.AppointmentItem
Dim oMeeting As MAPI.MeetingItem
Dim oRecurPat As MAPI.RecurrencePattern
Dim oMsgColl As Object
Dim oMsgFilter As MAPI.MessageFilter
Dim objInfoStore As Object
oSession = New MAPI.Session
Dim RtFolder As Object
Dim objFolders As Object
Dim ObjFolder As MAPI.Folder
Dim profile As String
profile = "dsr-dom.dsr.gov.au" + vbLf + "Administrator"
oSession.Logon(, , , , , , profile)
' Get your default information store
objInfoStore = oSession.GetInfoStore("")
' Get to the root folder
RtFolder = objInfoStore.RootFolder
' Loop through all the folders.
objFolders = RtFolder.Folders
ObjFolder = objFolders.GetFirst()
For Each ObjFolder In objFolders
Dim Nameval As String
Nameval = ObjFolder.Name
Console.WriteLine(Nameval)
Console.WriteLine("****************************")
If Nameval = "Calendar" Then
Read_Cal(oSession)
ElseIf Nameval = "Tasks" Then
Read_Tasks(oSession)
Else
Read_Mails(ObjFolder, oSession)
End If
Next
Console.Read()
End Sub
Public Sub Read_Cal(ByVal session As MAPI.Session)
Dim oCalendar As MAPI.Folder
Dim oMsgColl As MAPI.Messages
Dim oMsgFilter As MAPI.MessageFilter
Dim oAppt As MAPI.AppointmentItem
oCalendar = session.GetDefaultFolder(0)
oMsgColl = oCalendar.Messages
oMsgFilter = oMsgColl.Filter
oAppt = oMsgColl.GetFirst
Do While (Not oAppt Is Nothing)
Console.WriteLine(oAppt.StartTime + oAppt.Subject)
Console.WriteLine(oAppt.MeetingStatus)
Dim objSender As MAPI.AddressEntry
objSender = oAppt.Sender
Console.WriteLine(objSender.Name)
Dim oRcpts As Object
oRcpts = oAppt.Recipients
Dim i As Integer
For i = 1 To oRcpts.Count
Console.WriteLine(oRcpts.Item(i).Name)
Next
oAppt = oMsgColl.GetNext
Loop
End Sub
Public Sub Read_Tasks(ByVal session As MAPI.Session)
Dim oCalendar As MAPI.Folder
Dim oMsgColl As MAPI.Messages
Dim oMsgFilter As MAPI.MessageFilter
Dim oAppt As MAPI.Message
oCalendar = session.GetDefaultFolder(8)
oMsgColl = oCalendar.Messages
oMsgFilter = oMsgColl.Filter
Console.WriteLine()
oAppt = oMsgColl.GetFirst
Do While (Not oAppt Is Nothing)
Console.WriteLine(oAppt.Text + oAppt.Subject)
Dim objSender As MAPI.AddressEntry
objSender = oAppt.Sender
Console.WriteLine(objSender.Name)
Dim oRcpts As Object
oRcpts = oAppt.Recipients
Dim i As Integer
For i = 1 To oRcpts.Count
Console.WriteLine(oRcpts.Item(i).Name)
Next
oAppt = oMsgColl.GetNext
Loop
End Sub
Public Sub Read_Mails(ByVal ObjFolder As MAPI.Folder, ByVal oSession As MAPI.Session)
Dim oMsgColl As MAPI.Messages
Dim oMsgFilter As MAPI.MessageFilter
Dim iCnt As Integer
For iCnt = 1 To 6
Select Case iCnt
Case 1
Console.WriteLine("-----------------------------")
Console.WriteLine("Meeting Request")
Console.WriteLine("----------------------------")
oMsgColl = ObjFolder.Messages
oMsgFilter = oMsgColl.Filter
oMsgFilter.Type = MeetingRequestType
Dim iMt As MAPI.MeetingItem
iMt = oMsgColl.GetFirst
Do While (Not iMt Is Nothing)
Console.WriteLine(iMt.Text)
Console.WriteLine(iMt.Subject)
Console.WriteLine(iMt.ID)
iMt = oMsgColl.GetNext
Loop
oMsgColl = Nothing
oMsgFilter = Nothing
Console.WriteLine("-----------------------------")
Console.WriteLine("End Meeting Request ")
Console.WriteLine("----------------------------")
Case 2
Console.WriteLine("-----------------------------")
Console.WriteLine("Appointment")
Console.WriteLine("----------------------------")
oMsgColl = ObjFolder.Messages
oMsgFilter = oMsgColl.Filter
oMsgFilter.Type = AppointmentType
Dim iAppt As MAPI.AppointmentItem

'Throwing error in this statement Specified Type cast error
iAppt = oMsgColl.GetFirst
'Console.WriteLine(iAppt.Type)
Do While (Not iAppt Is Nothing)
'iAppt1 = oSession.GetMessage(iAppt.ID)
Dim appID As String
appID = iAppt.ID
iAppt1 = oSession.GetMessage(iAppt.ID)
Console.WriteLine(iAppt.ID)
Console.WriteLine(iAppt.Type)
Console.WriteLine(iAppt.Text)
Console.WriteLine(iAppt.Subject)
Console.WriteLine(iAppt.ID)
iAppt = oMsgColl.GetNext
Loop
oMsgColl = Nothing
oMsgFilter = Nothing
Console.WriteLine("-----------------------------")
Console.WriteLine("End Appointment ")
Console.WriteLine("----------------------------")

Case 3
Console.WriteLine("-----------------------------")
Console.WriteLine("MEssage Type")
Console.WriteLine("----------------------------")
oMsgColl = ObjFolder.Messages
oMsgFilter = oMsgColl.Filter
oMsgFilter.Type = MessageType
Dim iMsg As MAPI.Message
iMsg = oMsgColl.GetFirst
Do While (Not iMsg Is Nothing)
Console.WriteLine(iMsg.Text)
Console.WriteLine(iMsg.Subject)
Console.WriteLine(iMsg.ID)
iMsg = oMsgColl.GetNext
Loop
oMsgColl = Nothing
oMsgFilter = Nothing
Console.WriteLine("-----------------------------")
Console.WriteLine("End MEssage ")
Console.WriteLine("----------------------------")
Case 4
Console.WriteLine("-----------------------------")
Console.WriteLine("Tasks")
Console.WriteLine("----------------------------")
oMsgColl = ObjFolder.Messages
oMsgFilter = oMsgColl.Filter
oMsgFilter.Type = TasksType
Dim iTsks As MAPI.Message
iTsks = oMsgColl.GetFirst
Do While (Not iTsks Is Nothing)
Console.WriteLine(iTsks.Text)
Console.WriteLine(iTsks.Subject)
Console.WriteLine(iTsks.ID)
iTsks = oMsgColl.GetNext
Loop
oMsgColl = Nothing
oMsgFilter = Nothing
Console.WriteLine("-----------------------------")
Console.WriteLine("End Task ")
Console.WriteLine("----------------------------")
Case 5
Console.WriteLine("-----------------------------")
Console.WriteLine("Tasks")
Console.WriteLine("----------------------------")
oMsgColl = ObjFolder.Messages
oMsgFilter = oMsgColl.Filter
oMsgFilter.Type = TaskRequestType
Dim iTsks As MAPI.Message
iTsks = oMsgColl.GetFirst
Do While (Not iTsks Is Nothing)
Console.WriteLine(iTsks.Text)
Console.WriteLine(iTsks.Subject)
Console.WriteLine(iTsks.ID)
iTsks = oMsgColl.GetNext
Loop
oMsgColl = Nothing
oMsgFilter = Nothing
Console.WriteLine("-----------------------------")
Console.WriteLine("End Task Request")
Console.WriteLine("----------------------------")
Case 6
Console.WriteLine("-----------------------------")
Console.WriteLine("Notes")
Console.WriteLine("----------------------------")
oMsgColl = ObjFolder.Messages
oMsgFilter = oMsgColl.Filter
oMsgFilter.Type = StickyNoteType
Dim iStkNt As MAPI.Message
iStkNt = oMsgColl.GetFirst
Do While (Not iStkNt Is Nothing)
Console.WriteLine(iStkNt.Text)
Console.WriteLine(iStkNt.Subject)
Console.WriteLine(iStkNt.ID)
iStkNt = oMsgColl.GetNext
Loop
oMsgColl = Nothing
oMsgFilter = Nothing
Console.WriteLine("-----------------------------")
Console.WriteLine("End Notes")
Console.WriteLine("----------------------------")
End Select
Next
End Sub
End Module


Throwing an error while trying to assign a appointmentitem variable to the first message in the messages collection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Receiving Error Msg:Unable to cast object of type cesemj ASP.NET 2.0 Basics 2 March 4th, 2008 02:18 PM
Cast from string "" to type 'Double' is not dounme ADO.NET 1 March 8th, 2005 01:31 PM
problem in cast of type yoord SQL Language 1 October 18th, 2004 03:19 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.