VB.net Excel Add Read Outlook calendar appointments for today Microsoft.Office.Interop.Outlook

Hi

What VB.net code would I use to read through all appointments for today using the Microsoft.Office.Interop.Outlook namespace
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:
Hi,

Read all appointments for today.

Protected Sub Page_Load(sender As Object, e As EventArgs)
	If Not IsPostBack Then
		Dim application As New Outlook.Application()
		Dim folder As Outlook.Folder = DirectCast(application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar), Outlook.Folder)
		Dim todayAppointments As New List(Of Outlook.AppointmentItem)()

		For Each item As Outlook.AppointmentItem In folder.Items
			If item.Start.[Date] = DateTime.Now.[Date] Then
				todayAppointments.Add(item)
			End If
		Next

		For Each appt As Outlook.AppointmentItem In todayAppointments
			Response.Write("Subject: " + appt.Subject & " Start: " & appt.Start.ToString("g") & " End: " & appt.[End].ToString("g") & "</br>")

		Next
	End If
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CodeCruiserCommented:
Instead of looping through all appointments, you can restrict appointments

http://blogs.msdn.com/b/waltwa/archive/2007/03/14/finding-appointments-within-a-specific-timeframe.aspx
Lokesh B RDeveloperCommented:
Hi,

Use simple LINQ query as follows.

VB.NET Code
Private Sub GetAppointments()
	Dim application As New Outlook.Application()
	Dim folder As Outlook.Folder = DirectCast(application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar), Outlook.Folder)
	Dim todayAppointments As New List(Of Outlook.AppointmentItem)()

	Dim query = From p In folder.Items.Cast(Of Outlook.AppointmentItem)() Where p.Start.[Date] = DateTime.Now.[Date]p

	For Each appt As Outlook.AppointmentItem In query
		Response.Write("Subject: " + appt.Subject & " Start: " & appt.Start.ToString("g") & " End: " & appt.[End].ToString("g") & "</br>")
	Next
End Sub

Open in new window


C#.NET

  private void GetAppointments()
        {
            Outlook.Application application = new Outlook.Application();
            Outlook.Folder folder = (Outlook.Folder)application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
            List<Outlook.AppointmentItem> todayAppointments = new List<Outlook.AppointmentItem>();

            var query = from p in folder.Items.Cast<Outlook.AppointmentItem>()
                        where p.Start.Date == DateTime.Now.Date
                        select p;

            foreach (Outlook.AppointmentItem appt in query)
            {
                Response.Write("Subject: " + appt.Subject + " Start: " + appt.Start.ToString("g") + " End: " + appt.End.ToString("g") + "</br>");
            }
        }

Open in new window

Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks very much for the help
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.