Reading shared calenders like 'TestRig 1', 'TestRig 2', 'TestRig 3' using .GetSharedDefaultFolder() worked as a charm until
'TestRig 11' and 'Test Rig 12' where added 😢.
'TestRig11 and 12 you can find but not TestRig1 anymore, using 'TestRig 1' is almost same as 'TestRig 11' only the last char is new.
The Fix: 'TestRig 1' is a view name, so changing to the real mail address instead testrig1@mytestcenter.com and the problem was solved 😀
The Code:
-----------------------------------------------------------------------------------
Sub ReadCalendarFromOutlook(calName As String)
Dim application As New Microsoft.Office.Interop.Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myRecipient As Outlook.Recipient
CalDay1.Scroll2Time(Now)
CalDay1.SetupTimeLine()
CalDay1.ClearAllEvents()
lblCalInfo.Visible = False
If calName = "" Then
lblCalInfo.Visible = True
lblCalInfo.Text = "No Calendar available"
Exit Sub
End If
Try
myNamespace = application.GetNamespace("MAPI")
myRecipient = myNamespace.CreateRecipient(calName)
Catch ex As Exception
MsgBox("It looks like you are missing OutLook on the computer :(")
Exit Sub
End Try
Try
Dim folder As Outlook.Folder = DirectCast(application.Session.GetSharedDefaultFolder(myRecipient, Outlook.OlDefaultFolders.olFolderCalendar), Outlook.Folder)
Dim todayAppointments As New List(Of Outlook.AppointmentItem)()
' ------------- Get Appointment for Date selected --------------------------------
Dim query = From p In folder.Items.Cast(Of Outlook.AppointmentItem)() Where p.Start.[Date] = DateTimePicker1.Value.[Date]
' ------------- Get ReCurrent Appointment for Date selected --------------------------------
Dim q1 As Outlook._AppointmentItem
Dim query2 = From p In folder.Items.Cast(Of Outlook.AppointmentItem)()
For Each q1 In query2
If q1.IsRecurring Then
Dim aRecurrent As Outlook.RecurrencePattern = q1.GetRecurrencePattern
Dim dx As DateTime
' dx = New DateTime(DateTimePicker1.Value.Year, DateTimePicker1.Value.Month, DateTimePicker1.Value.Day, q1.Start.Hour, q1.Start.Minute, 0)
dx = DateTimePicker1.Value.[Date] + q1.Start.[TimeOfDay]
Dim ap As Outlook.AppointmentItem = Nothing
Try
' .GetOccurence() seems a bit strange, it returns ap=Nothing if a Appoinment is found ??? ELSE it returns a ComException
ap = aRecurrent.GetOccurrence(dx)
' ap = nothing, so we found an appointment
CalDay1.AddEvent(DateTimePicker1.Value.[Date] + q1.Start.[TimeOfDay], DateTimePicker1.Value.[Date] + q1.End.[TimeOfDay], q1.Subject + vbCrLf + q1.Location)
Catch ex1 As System.Runtime.InteropServices.COMException
' We end up here if appointment wasn't found for selected day
Debug.Print(ex1.Message)
Catch ex As Exception
Debug.Print(ex.Message)
End Try
Else
If q1.Start.[Date] = DateTimePicker1.Value.[Date] Then
CalDay1.AddEvent(q1.Start, q1.End, q1.Subject + vbCrLf + q1.Location)
End If
End If
q1 = Nothing
Next
Catch ex As Exception
Debug.Print("Error: " + ex.Message)
' NB: If you got error msg "Outlook does not recognize one or more names"
' Then use CalName="TestRig1@testcenter.com instead of "TestRig 1"
' When we added TestRig11 and 12, using "TestRig 1" stopped working.
lblCalInfo.Visible = True
lblCalInfo.Text = "Failed to read Calendar" + vbCrLf + calName
End Try
End Sub
Wednesday, September 25, 2019
Thursday, August 29, 2019
Weird .Net error Collection was modified; enumeration operation may not execute.
I got this error when closing a form, and it isn't pointing to a certain line of code it just happens.
The code has been running without problem for more than 5 year. But then I had to change from Win7 VS2013 to Win10 VS2017, BAM! I got this error.
System.InvalidOperationException
HResult=0x80131509
Message=Collection was modified; enumeration operation may not execute.
Source=mscorlib
StackTrace:
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at Microsoft.VisualBasic.PowerPacks.ShapeCollection.Dispose(Boolean disposing)
at Microsoft.VisualBasic.PowerPacks.ShapeContainer.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at System.Windows.Forms.Control.Dispose(Boolean disposing)
at System.Windows.Forms.ContainerControl.Dispose(Boolean disposing)
at MN_Bargraph.MN_BarGraph.Dispose(Boolean disposing) in C:\MN_Bargraph\UserControl1.Designer.vb:line 13
It said something about .Designer.vb line 13
So I comment out the line as shown below
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
'MyBase.Dispose(disposing)
End Try
End Sub
The code has been running without problem for more than 5 year. But then I had to change from Win7 VS2013 to Win10 VS2017, BAM! I got this error.
System.InvalidOperationException
HResult=0x80131509
Message=Collection was modified; enumeration operation may not execute.
Source=mscorlib
StackTrace:
at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
at System.Collections.Generic.List`1.Enumerator.MoveNext()
at Microsoft.VisualBasic.PowerPacks.ShapeCollection.Dispose(Boolean disposing)
at Microsoft.VisualBasic.PowerPacks.ShapeContainer.Dispose(Boolean disposing)
at System.ComponentModel.Component.Dispose()
at System.Windows.Forms.Control.Dispose(Boolean disposing)
at System.Windows.Forms.ContainerControl.Dispose(Boolean disposing)
at MN_Bargraph.MN_BarGraph.Dispose(Boolean disposing) in C:\MN_Bargraph\UserControl1.Designer.vb:line 13
It said something about .Designer.vb line 13
So I comment out the line as shown below
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
'MyBase.Dispose(disposing)
End Try
End Sub
Now no errors, why this works or what the designer.vb code does, don't ask me.
I'm happy and clueless, good enough for me for now 😂
Wednesday, January 09, 2019
Share folder C$ failes with 'access denied'
Sometimes you fail to access other computers C: drive using \\computername\c$
Add or update the following on the computer you want have access to:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
create or modify 32-bit DWORD: LocalAccountTokenFilterPolicy
set the value to: 1
Info was found here
Subscribe to:
Posts (Atom)
MySQL to MariaDB
Here is a good description how to migrate to MariaDb MySQL to MariaDb Example of how to dump data from MySQL port=3307: mysqldump --user=ro...
-
When converting an VB2008 application to VB2010 I run into trouble regarding COM objects while compiling. you get errors like: Error 1...
-
In a module you have declared a Structure or Enum that you will use through out a project. Module Module1 Public Structure dummy ...
-
Apache2 crashes on Ubuntu Linux 22.04.5 after Zabbix was updated to 7.0.26 During a upgrade of my Ubuntu server there was a new package for ...