For a calendar event, MapiCalendar.ItemId seems to be empty

Hello,
I am trying to get the identifier for a meeting event using the following code.

var calEvent = message.ToMapiMessageItem() as MapiCalendar;
string itemId = calEvent.ItemId;

For all the meeting events in the pst file, the itemId is coming out to be empty.
I am able to get other properties for that object like event subject, organizer, attendees etc.

Any ideas how to get the unique identifier for a meeting event?

Thanks,
Vijay

@vijaykr

It seems that you are encountering an issue where the ItemId property of the MapiCalendar object is returning empty for meeting events. This can happen for a few reasons, particularly related to how the calendar items are stored in the PST file.

Here are a few suggestions to help you troubleshoot and potentially resolve this issue:

  1. Check the Source of the Calendar Item: Ensure that the calendar events you are trying to access are indeed stored in the PST file and are not being retrieved from another source (like an online calendar).

  2. Verify the PST File: Sometimes, the PST file may be corrupted or not properly formatted. Try opening the PST file in Outlook to see if the events display correctly there.

  3. Use Different Properties: If ItemId is not available, you might want to check other properties that can uniquely identify the calendar event. For example, properties like GlobalUniqueId or EntryId might be available and can serve as unique identifiers.

  4. Review the Code: Ensure that the code you are using to convert the message to a MapiCalendar is correct. You might want to double-check the conversion process and ensure that the calendar item is being properly instantiated.

  5. Consult Documentation or Support: If the issue persists, consider checking the Aspose documentation or reaching out to their support forum for more specific guidance related to the MapiCalendar class and its properties.

If you have any further details or specific scenarios, feel free to share them, and I can assist you further!

Sources:
[1]: CreateMapiCalendarTimeZoneFromStandardTimezone.cs

Thanks for your response. I think the pst file seems fine since I am able to get the other properties for the meeting event like subject, attendees, organizer, body, location etc. You mentioned that I can use alternative properties likeGlobalUniqueId or EntryId.

Can you provide some examples of how I may be able to access these properties? I don’t see these being available on a MapiCalendar object.

Also, this is how I convert a message to MapiCalendar.

var calEvent = message.ToMapiMessageItem() as MapiCalendar;

Let me know if this isn’t the right approach.

Thanks,
Vijay

@vijaykr,

ItemId is a property that identifies a message on a server, not in a PST.
You need to use the EntryId property, which identifies messages in PST.
The EntryId can be obtained during the messageInfo enumeration stage:

foreach (var messageInfo in folder.EnumerateMessages())
{
    if (messageInfo.MessageClass == "IPM.Appointment")
    {
        var calEntryId = messageInfo.EntryId;
    }
}

Thank you.

Thanks Margarita. That helped.

Also, what is the best way to read MapiCalendarRecurrencePatternType MapiCalendarRecurrencePattern.PatternType? I noticed we have an annual event for Christmas day but the PatternType I get back is Month when I use the above property.

Thanks,
Vijay

Hello @vijaykr,

Aspose.Email reads the structure as described in the MS documentation, which can be found at Microsoft Docs - PatternType.

As you can see, there is no specific type for “Year” in the PatternType field. It is likely that “Month” indicates the event recurs in a specific month.

On the other hand, the Frequency property clearly shows that the recurrence is yearly.

Thank you.

Thanks Margarita.

I am trying to validate that I am able to get all the calendar data from the code I have written. To do this validation, I opened the pst file in Outlook directly and tried to scan through the calendar data that shows on Outlook and did a spot check to see if those are showing up on the data I am pulling from code. It appears like though there are some calendar events that are getting pulled up but appears like most calendar items are not. Can you scan through the logic I have and let me know what could be going wrong?

PersonalStorage personalStorage = PersonalStorage.FromFile(pstFilePath);
FolderInfo folderInfo = personalStorage.RootFolder;

MessageInfoCollection messages = folderInfo.GetContents();
foreach (MessageInfo messageInfo in messages)
{
MapiMessage message = personalStorage.ExtractMessage(messageInfo);
{
if (message.MessageClass == “IPM.Appointment”)
{
var calEvent = message.ToMapiMessageItem() as MapiCalendar;

   /* Add the needed info to logs */
}

}
}

With the code above, I am getting about 50 of the calendar events. But when looking from Outlook calendar directly, there are 1000s of events that I have in the calendar.

I tried to log the folder name and message count in that folder through a console log.
Console.WriteLine("Folder: " + folderInfo.DisplayName + ", Message Count: " + messages.Count);

For Calendar folder, I get this:
Folder: Calendar, Message Count: 50

A bunch of other folders are also showing the message count as 50.
Folder: United States holidays, Message Count: 50
Folder: Contacts, Message Count: 50

I know there are more than 50 contacts for sure. Something isn’t correct. Across all the folders that are getting read, the max I items I am seeing under every folder is 50 and not more than that. (a lot of them have less than 50 but 50 is the max for some reason). I check Sent Items mail count as well and that is coming out to be 50 too.
Folder: Sent Items, Message Count: 50

What do I need to do to ensure I am not missing out on any events? And why aren’t all the events in the calendar getting picked up with the above code and only some are coming through? I am hoping all the events in a calendar are of type IPM.Appointment. [BTW I also tried to pull IPM.Schedule.meeting items but there are none. So my guess is IPM.Appointment is the right way to pull the calendar events].

Any suggestions on what would be the best way to validate that the code is pulling all the events and not missing any?

Thanks,
Vijay

Hello @vijaykr ,

You have encountered a license limitation. The trial version (without license) limits the number of extracted items to 50. For more complete testing you can request a temporary license.

Thanks Margarita for your assistance. I will do that.

Thanks,
Vijay

@vijaykr ,

You’re welcome! Feel free to contact us with any product questions, at any time.

Thanks Margarita for your help.

Which properties do I use to identify if a meeting/event has been marked as private?
Additionally, how do I get the correct free/busy/tentative/out of office status on an event? I tried to read the MapiCalendar.BusyStatus, but that is always coming back as Tentative for all the calendar events.

Thanks,
Vijay

@vijaykr ,

To determine if a meeting or event has been marked as private and to get the status, you can use the following properties:

  1. Use the property MapiCalendar.Sensitivity to check the sensitivity of the event. The sensitivity levels can be:

    MapiSensitivity.Normal: The event is not private.
    MapiSensitivity.Personal: The event is personal.
    MapiSensitivity.Private: The event is private.
    MapiSensitivity.Confidential: The event is confidential.
    
  2. The property MapiCalendar.BusyStatus represents the status of the event, such as Free, Busy, Tentative, or Out of Office. If you are consistently getting incorrect value, it might be worth checking the source of the data or verifying if the event statuses are correctly set in the source file. Additionally, ensure that the events you’re testing against have diverse statuses set in the actual calendar to see the different BusyStatus values.

Thanks Margarita.

I was testing out whether I am getting all the calendar items correctly by reading from the pst file through code vs loading the pst in Outlook directly.

I noticed there is some level of mismatch. On Outlook calendar I am seeing more calendar events that what I get back from code using MapiCalendar. For eg, for 1 specific day I looked at, I saw Outlook calendar has 2 events listed but I am not getting any calendar events in code. For another day, I saw Outlook calendar had 11 events, where as I am getting only 7 events from code.

Any ideas on why there is a mismatch? The code I am using is same as I have listed in earlier messages.

Additionally, when I try to get the body of a calendar event using MapiCalendar.Body, it seems to be null but the MapiCalendar.BodyHtml has details about the body. When is body null and how can I get the details about the meeting?

Thanks,
Vijay

@vijaykr,

For recurring events, Outlook displays each occurrence, while the PST file stores only the recurring series as a single event.

For the issue with MapiCalendar.Body returning null, it’s possible that the plain text version of the event body (Body) was not set when the event was created or saved. Some calendar entries only store the HTML version of the body (BodyHtml).
You can check MapiCalendar.Body, and if it is null, convert the HTML content to plain text if necessary.

Thank you.

Thanks Margarita.

I will use the BodyHtml property to get the body.

For recurring events, since Outlook displays each occurrence, is there a way to get the same info from PST? How do I replicate that in code?

If Outllok shows 10 events for a day in its calendar, I want to get the same count for the number of events and the details for the events through code. Would you have some sample code for that?

Thanks,
Vijay

@vijaykr ,

Aspose.Email does not provide a method for getting occurrences. Instead, you’ll need to manually handle recurrence patterns.

To achieve this, please do the following:

  • Check if the MapiCalendar has recurrence
  • Use the recurrence pattern to calculate each occurrence’s start and end times.
  • Compare these calculated times against your specified date range.

Thanks Margarita. I implemented what you mentioned. Mostly the data matches with what I see on Outlook calendar. There are a few that are still missing. I spot checked one of those recurring events that show up on Outlook but not in my data. The specific event has recurrence pattern of every Tuesday from 11/14/2003 from 8-9am. (attached image) (and no end date specified)
image.png (2.3 KB)

In code, I get:
calendarEvent.Recurrence.RecurrencePattern.PatternType as “Week”
calendarEvent.Recurrence.RecurrencePattern.OccurrenceCount as 0
calendarEvent.Recurrence.RecurrencePattern.Period as 1

Why is the OccuranceCount coming out as 0 when it should have infinite occurances? Is that because there is no end date specified for the event? (it happens every Tuesday)

How can we handle such cases in code? Any suggestions?

Thanks,
Vijay

@vijaykr ,

Yes, the OccurrenceCount value being 0 indicates that the event has no predefined end or specific number of occurrences. This is expected behavior for events with an infinite recurrence, like the one you described (weekly on Tuesdays starting from 11/14/2003 with no end date). Since there’s no limit to the number of occurrences, the OccurrenceCount is not set explicitly in the data.

In Outlook and many calendar systems, when no end date is specified, the event is treated as recurring indefinitely. However, for practical purposes (such as display or data export), there is usually a need to limit how many instances are generated. Typically, calendars or APIs will return only occurrences within a reasonable date range (e.g., the next year).

  • If OccurrenceCount is 0 and no end date is provided, you can manually set a reasonable limit in your code to handle these cases. For example, generate occurrences for the next 10 years or until a certain maximum date.
  • Or use the recurrence pattern to dynamically calculate occurrences within a desired range. For example, if you’re dealing with an event starting in 2003, you could calculate all Tuesdays between 11/14/2003 and the current date or another range you’re interested in.

I hope it helps. Please spare a minute to share your feedback.

Thanks Margarita.

I have a MapiCalendar object that I get from reading a PST file. I have some meetings that are of PatternType “MonthNth”. Some of them happen first (or second) Tuesday of the month and some other meetings that happen the last Friday of the month for example.

As you suggested previously, I replicate the recurring events on my side since PST only stores once instance. How do I find out which day of the month is the MonthNth pattern type event recurring? I can get the day of the month when it recurs by getting the day of the first event. But how do I find which x-day of the month it repeats? There is a property called Aspose.Email.Calendar.Recurrences.DayPosition which seems to be for that purpose but how do a Get on that property?
calendarEvent.png (30.2 KB)

//calendarEvent is a MapiCalendar object
I can’t seem to do a get on calendarEvent.Recurrence.DayPosition and I get this error:
error CS1061: ‘MapiCalendarEventRecurrence’ does not contain a definition for ‘DayPosition’ and no accessible extension method ‘DayPosition’ accepting a first argument of type ‘MapiCalendarEventRecurrence’ could be found (are you missing a using directive or an assembly reference?)

The DayPosition property shows up on the debugger variables as depicted in the image but I am unable to do a get on it.

Any ideas?

Thanks,
Vijay

Hello @vijaykr,

We have created a ticket to investigate the issue further. The ticket id is EMAILNET-41436.

We will keep you updated on our findings. Thank you for your patience.

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.