Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have done the following code to save a recurring entry to Calendar List named Bookings.

    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["EventDate"] = startdate;//11/09/2012 08:00:00
            recEvent["EndDate"] = enddate;//11/09/2012 08:30:00
            recEvent["Booking_x0020_Title"] = Convert.ToString(txtTitle.Text);
            recEvent["Title"] = Convert.ToString(txtTitle.Text);
            recEvent["RecurrenceData"] = Recur_Xml.ToString();//ReccurrenceRule
            recEvent["fRecurrence"] = "True";
            recEvent["EventType"] = 1;
            recEvent["UID"] = System.Guid.NewGuid();
            recEvent["TimeZone"] = 0;
            recEvent["Recurrence"] = -1;
            recEvent["XMLTZone"] = "<timeZoneRule><standardBias>-330</standardBias><additionalDaylightBias>-60</additionalDaylightBias></timeZoneRule>";

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

        }

If i save the above with Recurrence rule as Repeat every 1 day for 10 occurences than the Item is saved properly and Current Events view shows all the instances but while fetching the Recurring entry i get only 1 Result i.e on Start Date. The following is the Code to retrieve recurrent values:

SPWeb oWeb = SPContext.Current.Web;
                SPList oListBookings = oWeb.Lists.TryGetList("Bookings");
SPQuery oQueryBookings = new SPQuery();

                            string strQuery = "";
    strQuery = @"<Where><DateRangesOverlap><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='RecurrenceID' /><Value Type='DateTime'><Today /></Value></DateRangesOverlap></Where>";
                            oQueryBookings.ExpandRecurrence = true;
                            oQueryBookings.Query = strQuery;
                            oQueryBookings.CalendarDate = date;
    SPListItemCollection oCollBookings = oListBookings.GetItems(oQueryBookings);

The result is shown only if oQueryBookings.CalendarDate = date; equals 11/09/2012 08:00:00 and it does not return any items for Dates after that even when the instances are present for these dates till 19/09/2012 08:00:00

The query returns all the item if i set the recEvent["EndDate"] to 19/09/2012 08:00:00 while saving the item. I want the EndDate for recurring items to be set to same day on user form (no user would want to calculate the last date of his occurence for recurring pattern with no end date) and it should be autocalculated on save.How is that possible?

If i make the entry using sharepont UI than this End date is autocalculated even if it is set to the same day and if its a recurring entry.

Please guide where am i going wrong? Is it while saving or while fetching the records? or is it because the EndDate is the same date as StartDate? Kindly help.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

The issue was because Start Date and End Date were on same day. Customised code from Code Project to calculate end date as per recurring pattern.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.