Q:

Issue with adding recurring entries programatically in Sharepoint Calendar list

I am saving recurring  calendar events programatically. Here is my code.
SPSite site = new SPSite(SPContext.Current.Web.Url);
            using (SPWeb web = site.OpenWeb())
            {
                SPList list = web.Lists["Bookings"];
                SPListItem recEvent = list.Items.Add();
                try
                {
                    recEvent["Attendees_x0020_Number"] = "5";

                    #region startdate
                    string strtDate = txtStartDate.Text;
                    string day = strtDate.Substring(0, 2);
                    string month = strtDate.Substring(3, 2);
                    string year = strtDate.Substring(6, 4);
                    string hour = ddlStrtHour.SelectedValue;
                    //string hour_int = hour.Split(' ')[0];
                    //string am_pm = hour.Split(' ')[1];
                    string mins = ddlStrtMins.SelectedValue;

                    string s = txtStartDate.Text + " " + hour + ":" + mins + ":00 ";
                    //DateTimeFormatInfo fi = new CultureInfo("en-US", false).DateTimeFormat;
                    //DateTime BookingStart = DateTime.ParseExact(s, "dd.MM.yyyy hh:mm:ss tt", fi);

                    string format = "dd/MM/yyyy HH:mm:ss";
                    //DateTime startdate = DateTime.ParseExact(s, format, System.Globalization.CultureInfo.InvariantCulture);
                    DateTime startdate = new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day), Convert.ToInt32(hour), Convert.ToInt32(mins), 0);
                    #endregion
                    recEvent["EventDate"] = startdate;//Booking Start
                    #region enddate
                    string endDate = txtEndDate.Text;
                    string endday = endDate.Substring(0, 2);
                    string endmonth = endDate.Substring(3, 2);
                    string endyear = endDate.Substring(6, 4);
                    string endhour = ddlEndHours.SelectedValue;
                    //string endhour_int = endhour.Split(' ')[0];
                    //string endam_pm = endhour.Split(' ')[1];
                    string endmins = ddlEndMins.SelectedValue;

                    string ends = txtEndDate.Text + " " + endhour + ":" + endmins + ":00 ";
                    //DateTimeFormatInfo endfi = new CultureInfo("en-US", false).DateTimeFormat;
                    //DateTime BookingEnd = DateTime.ParseExact(ends, "dd.MM.yyyy hh:mm:ss tt", endfi);

                    //DateTime enddate = DateTime.ParseExact(ends, format, System.Globalization.CultureInfo.InvariantCulture);
                    DateTime enddate = new DateTime(Convert.ToInt32(endyear), Convert.ToInt32(endmonth), Convert.ToInt32(endday), Convert.ToInt32(endhour), Convert.ToInt32(endmins), 0);
                    #endregion
                    recEvent["EndDate"] = enddate;//Booking End

                    #region Meeting startdate
                    string Meetinghour = ddlStrtHour_Meeting.SelectedValue;
                    string Meetingmins = ddlStrtMins_Meeting.SelectedValue;

                    string Meetings = txtStartDate.Text + " " + hour + ":" + mins + ":00 ";
                    DateTime Meetingstartdate = new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day), Convert.ToInt32(Meetinghour), Convert.ToInt32(Meetingmins), 0);
                    #endregion
                    recEvent["Booking_x0020_Start"] = Meetingstartdate;
                    #region meeting enddate
                    string Meetingendhour = ddlEndHours_Meeting.SelectedValue;
                    string Meetingendmins = ddlEndMins_Meeting.SelectedValue;

                    string Meetingends = txtEndDate.Text + " " + Meetingendhour + ":" + Meetingendmins + ":00 ";
                    //DateTimeFormatInfo endfi = new CultureInfo("en-US", false).DateTimeFormat;
                    //DateTime BookingEnd = DateTime.ParseExact(ends, "dd.MM.yyyy hh:mm:ss tt", endfi);

                    //DateTime enddate = DateTime.ParseExact(ends, format, System.Globalization.CultureInfo.InvariantCulture);
                    DateTime Meetingenddate = new DateTime(Convert.ToInt32(endyear), Convert.ToInt32(endmonth), Convert.ToInt32(endday), Convert.ToInt32(Meetingendhour), Convert.ToInt32(Meetingendmins), 0);
                    #endregion
                    recEvent["Booking_x0020_End"] = Meetingenddate;

                    recEvent["Booking_x0020_Title"] = Convert.ToString(txtTitle.Text);
                    recEvent["Recurrence_x0020_ID"] = 5;
                    recEvent["Title"] = Convert.ToString(txtTitle.Text);
                    recEvent["RecurrenceData"] = Recur_Xml.ToString();
                    recEvent["EventType"] = 1;
                    recEvent["UID"] = System.Guid.NewGuid();
                    recEvent["TimeZone"] = 13;
                    recEvent["Recurrence"] = -1;
                    recEvent["XMLTZone"] = "<timeZoneRule>" +
                        "<standardBias>480</standardBias>" +
                        "<additionalDaylightBias>-60</additionalDaylightBias>" +
                        "<standardDate><transitionRule  month='10' day='su' weekdayOfMonth='last' />" +
                        "<transitionTime>2:0:0</transitionTime></standardDate>" +
                        "<daylightDate><transitionRule  month='4' day='su' weekdayOfMonth='first' />" +
                        "<transitionTime>2:0:0</transitionTime>" +
                        "</daylightDate></timeZoneRule>";

                    recEvent.Update();
                }
                catch (Exception er)
                {

                }

I am facing issue when i add a new event which is recurring Daily Every Weekday and End After 10 Occurances, the Reccurence rule formed is
<recurrence><rule><firstDayOfWeek>su</firstDayOfWeek><repeat><daily weekday="TRUE" /></repeat><repeatInstances>10</repeatInstances></rule></recurrence>

But when i look at the Calendar view than i get the entries Starting on next day of the start date as seen in fig: I had set Start Date as 10/09/2012 but the event starts from 11/09/2012 and weekdays are considered from Tuesday to Saturday instead of Monday To Friday. I dont know why this is happening.

The view which consists of all instances of recurring items:

Please help me to sort out why the week days are considered from Tuesday to Friday, this issue happens only when i add entry programatically, works fine when adding event through Sharepoint UI.also why is Start Date gets saved as 11/09/2012 when the input was  10/09/2012?

A:

The issue was with setting the TimeZone while saving. Remove it/ Set it correctly. Should work fine

