1

I am copying lists from SharePoint online to local SQL server for generating reports locally.

One of those lists is a Calendar list. This list contains some recurring events. but when i get all items of the list with CamlQuery.CreateAllItemsQuery() only on item per recurring event is present(the first occurrence). I found some solutions like this and this to get all recurrence events. But all of them are using SSOM code.

I found a field called RecurrenceData but it contains a bunch of XML data which is not helping me in storing all the events to DB.

How do I get all items of a calendar list using CSOM code?

Update:

I found a solution on github by MartinBodocky using Javascript CSOM. How can i write a similar piece of code in C#?

The function is as below

GetItemsFromCalendarAsmx = function (webUrl, calendarGuid) {

    wsURL = webUrl + "_vti_bin/Lists.asmx";

    var xmlCall =
        "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> <soap:Body>" +
        "<GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>" +
        "<listName>" + calendarGuid + "</listName>" +
        "<query>" +
        "<Query>" +
        "<Where>" +
           "<DateRangesOverlap>" +
           "<FieldRef Name=\"EventDate\" />" +
           "<FieldRef Name=\"EndDate\" />" +
           "<FieldRef Name=\"RecurrenceID\" />" +
           "<Value Type='DateTime'><Year/></Value>" +
           "</DateRangesOverlap>" +
        "</Where>" +
        "</Query>" +
        "</query>" +
        "<queryOptions>" +
        "<QueryOptions>" +
            "<ExpandRecurrence>TRUE</ExpandRecurrence>" +
        "</QueryOptions>" +
        "</queryOptions>" +
        "</GetListItems>" +
        "</soap:Body></soap:Envelope>";
    var result = [];
    $.ajax({
        url: wsURL,
        type: "POST",
        dataType: "xml",
        async: false,
        data: xmlCall,
        complete: function (xData, status) {
            Core.LogMessage("Core.GetItemsFromCalendarAsmx-> url: " + wsURL + " status: " + status);
            if (status === "success") {
                var root = $(xData.responseText);
                root.find("listitems").children().children().each(function () {
                    $this = $(this);
                    var ids = $this.attr("ows_UniqueId").split(";");
                    var rec = $this.attr("ows_fRecurrence");
                    result.push({
                        "StartTime": $this.attr("ows_EventDate"),
                        "EndTime": $this.attr("ows_EndDate"),
                        "Title": $this.attr("ows_Title"),
                        "Recurrence": (rec === "1" ? true : false),
                        "Description": Core.HtmlDecode($this.attr("ows_Description")),
                        "Guid": ids[1],
                        "Id": ids[0],
                    });
                });
            }
        },
        contentType: "text/xml; charset=\"utf-8\""
    });
    return result;
};

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.