Free Support Forum - aspose.com

Not able to set Calendar Timezone

I am trying to set Timezone property for calendar using below code:

Appointment f_objAppointment = null;
f_objAppointment = new Appointment(f_Location, p_AppointmentObj.Subject, f_Body, f_StartDate,
f_EndDate, new MailAddress("test@gmail.com"),
MailMessage f_objMsg = new MailMessage();
f_objMsg.AddAlternateView(f_objAppointment.RequestApointment());
f_objMapiMsg = MapiMessage.FromMailMessage(f_objMsg);
MapiCalendar f_MapiCalendarObj = (MapiCalendar)f_objMapiMsg.ToMapiMessageItem();
f_MapiCalendarObj.SetProperty(KnownPropertyList.CalendarTimeZone,
“(UTC+13.00) Samoa”);

But it is not setting the default Timezone property of outlook, instead its creating one new property tag and assigning the value. Please refer the attachment Timezone.PNG (110.0 KB)

Is there any way to set 0X80B1 Timezone ?

@Shital_diwate,

Following is a sample code where timezone property is set for calendar. Please give it a try and share the feedback.

// Declare the pst file
string pstFileName = @"calendar.pst";
if (File.Exists(pstFileName))
    File.Delete(pstFileName);

// Create the appointment
MapiCalendar appointment = new MapiCalendar(
    "LAKE ARGYLE WA 6743",
    "Appointment",
    "This is a very important meeting :)",
    new DateTime(2015, 7, 12, 13, 0, 0),
    new DateTime(2015, 7, 12, 14, 30, 0));

// Create the timezone (Romance Standard Time - Europe/Paris)
MapiCalendarTimeZoneRule daylightTransitionTime = new MapiCalendarTimeZoneRule
{
    Hour = 2,
    Milliseconds = 0,
    Minute = 0,
    Month = 3,
    Seconds = 0,
    Year = 0,
    DayOfWeek = DayOfWeek.Sunday,
        Position = DayPosition.Last
};
MapiCalendarTimeZoneRule standardTransitionTime = new MapiCalendarTimeZoneRule
{
    Hour = 3,
    Milliseconds = 0,
    Minute = 0,
    Month = 10,
    Seconds = 0,
    Year = 0,
    DayOfWeek = DayOfWeek.Sunday,
    Position = DayPosition.Last
};
MapiCalendarTimeZoneInfo mapiCalendarTimeZoneInfo = new MapiCalendarTimeZoneInfo
{
    Bias = -60,
    StandardBias = 0,
    DaylightBias = -60,
    DaylightDate = daylightTransitionTime,
    StandardDate = standardTransitionTime,
    Year = 1601
};
MapiCalendarTimeZone mapiCalendarTimeZone = new MapiCalendarTimeZone
{
    KeyName = "Romance Standard Time",
    TimeZoneRules = new MapiCalendarTimeZoneInfoCollection { mapiCalendarTimeZoneInfo }
};

// Set the timezones in the appointment
appointment.StartDateTimeZone = mapiCalendarTimeZone;
appointment.EndDateTimeZone = mapiCalendarTimeZone;

// Create the pst and add the appointment to folder "Calendar"
PersonalStorage pst = PersonalStorage.Create(pstFileName, FileFormatVersion.Unicode);
FolderInfo calendarFolder = pst.CreatePredefinedFolder("Calendar", StandardIpmFolder.Appointments);
calendarFolder.AddMapiMessageItem(appointment);

// Read back the appointment from the pst
FolderInfo calendar = pst.GetPredefinedFolder(StandardIpmFolder.Appointments);
MessageInfoCollection messages = calendar.GetContents();

// Get the mapi calendar objects
MapiMessage[] mapiMessages = messages.Select(msg => pst.ExtractMessage(msg.EntryId)).ToArray();
MapiCalendar[] mapiCalendars = mapiMessages.Select(mapiMessage =>
    (MapiCalendar)mapiMessage.ToMapiMessageItem()).ToArray();

I have tried with the above code and it is setting the time zone properly.
But when am setting recurrence property to the calendar, time zone is not getting assigned.
Please suggest on this.

@Shital_diwate,

Could you please share your sample code which is working fine without setting the recurrence and having issue while setting the recurrence? Please send us the compilable console application where no reference is missing for our testing here.

I am attaching the test application here:
Timezone.zip (2.6 MB)

  1. Without setting recurrence property. Time zone is getting assigned.
    NoRec.PNG (79.4 KB)

  2. With recurrence property. Time zone is not getting assigned.
    Rec.PNG (85.9 KB)

@Shital_diwate,

In case of recurrence, you may please set the MapiCalendarEventRecurrence.TimeZoneStruct as shown in the following sample code. Please give it a try and share the feedback.

f_mapiCalevntrec.TimeZoneStruct = mapiCalendarTimeZone;

MapiCalendarDailyRecurrencePattern f_mapiCalenderDailyRecPat = new MapiCalendarDailyRecurrencePattern();
f_mapiCalenderDailyRecPat.PatternType = MapiCalendarRecurrencePatternType.Day;
f_mapiCalenderDailyRecPat.DayOfWeek = MapiCalendarDayOfWeek.Friday;
f_mapiCalenderDailyRecPat.EndType = MapiCalendarRecurrenceEndType.EndAfterNOccurrences;
f_mapiCalenderDailyRecPat.OccurrenceCount = 10;
f_mapiCalenderDailyRecPat.StartDate = DateTime.Today;
f_mapiCalenderDailyRecPat.Period = 1;



MapiCalendarEventRecurrence f_mapiCalevntrec = new MapiCalendarEventRecurrence();
f_mapiCalevntrec.RecurrencePattern = f_mapiCalenderDailyRecPat;
f_mapiCalevntrec.ClipEnd = DateTime.Today.AddDays(10);
f_mapiCalevntrec.ClipStart = DateTime.Today;
f_mapiCalevntrec.TimeZoneStruct = mapiCalendarTimeZone;//NOTE THIS LINE
appointment.Recurrence = f_mapiCalevntrec;

Okay. We have tried the given option.
Now it is showing Timzone set with highlighting the Timzone option
image.png (6.9 KB)

But it is not setting the timezone which we are giving .

As you can see in the following image ,we are giving "Samoa Standard Time "., but when we are opening the resultant pst it is showing (utc-5)
image.png (13.9 KB)

image.png (67.7 KB)

It was observation that previously in Outlook Spy it is giving UTC-5 as Timezone.

@Shital_diwate,

Thank you for providing feedback.

This issue is observed and logged under Id: EMAILNET-38953 for further investigation. We will analyze it on its turn and write back here once feedback is ready to share.

Hello @kashif.iqbal ,
is there any update or fixes regarding this issue ?

@Shital_diwate,

Thank you for getting back to us. This issue has long been created and closed. Can you please try using latest Aspose.Email for .NET 20.2 on your end and share if there is still an issue. In observations of ticket, it has been shared by our team that Calendar does not support arbitrary KeyName for MapiCalendarTimeZone. If set the MapiCalendarTimeZone.KeyName property only to “UTC-11” (not “(UTC-11:00) Coordinated Universal Time-11”!), the time zone in the calendar becomes correct. So, for UTC-11 the appropriate name is “Samoa Standard Time”. You can visit this link for Timezone names.

hello @mudassir.fayyaz,

I am trying to set Time zone to mapicalendar which displays correct in outlook 2007 as per given time and time zone name also checked in outlook spy too. But when i check same file in outlook 2010 and above version then time zone is missing.

Note: I am using Aspose.Email for .NET vesrion 20.2

image.png (19.8 KB)

@Shital_diwate,

I have observed the image shared by you and request you to please provide a working sample code along with source file (if any) and generated output. Please also share the snapshot of issue incurring on your when viewing in Outlook.

@mudassir.fayyaz,

PFA sample code also attaching outlook 2007 screenshot and outlook 2016 screenshotTimeZoneIssue.zip (2.7 MB)
Timezone_in_outlook2007.png (129.1 KB)
Timezone_in_outlook2016.png (121.8 KB)

@Shital_diwate,

I have observed the issue shared by you and it seems to be a new issue. I have created an issue with ID EMAILNET-39794 in our issue tracking system as enhancement to further investigate and resolve it. This thread has been linked with the issue so that you may be notified once the issue will be fixed.

@mudassir.fayyaz,

is there any update or fixes regarding this issue ? when can i expect the fixes?

@Shital_diwate,

I have verified from our issue tracking system and regret to share that at present the issue is not resolved. We will share the good news with you as soon as it will be fixed.

@Shital_diwate,
I made some changes to your project and now it works correctly, please check and give feedbackTimeZoneIssue1.zip (2.7 MB)

@alecs555,

Sory for late reply , i checked above code now time zone is showing but time are getting modify .

outlook 2007 it is showing correct
image.png (258.8 KB)

But in outlook 2010 and above time is showing wrong
image.png (169.3 KB)

Also above code is not generic for all the calendar events like recurrence event . not in normal event for other timezone.

We are looking for more generic solution which shows correct time and timezone for all type of events.
( i.e. Recurrence as well as non-recurrence)

@Shital_diwate,

Thank you for sharing the feedback. I have added the information in our issue tracking system and will get back to you as soon as issue will be addressed.

@Shital_diwate,

We are working further on your issue and require some help from you on your end.

First question - what Time Zone on his machine where you are running the app? Please share the snapshot and details with us.

Also, can you please try following steps on your end:

1: Comment line of code with seting EndDateTimeZone of MapiCalendar in our last project TimeZoneIssue1 shared wit you.

    //f_MapiCalendarObj.EndDateTimeZone = EndtimeZone;

2: Run TimeZoneIssue1.

3: Open resultant PST file in Outlook 2010 or above, go to Calendar, open created appointment and make screenshot. Then send this screenshort to us.