none
Reading the SharePoint calendar recurring events using lists.asmx from c# is not working RRS feed

  • Question

  • Hi,

    I'm trying to read SharePoint calendar events including recurring events using lists.asmx from c#. When I run the lists service from c#, its returning only main events not recurring events. If I run same script/code from an html file, its returning all the events.

    Can you  please help on this? Is it possible to expand the recurring events from c# using lists.asmx?

    Thanks

    Ramesh

    • Moved by DotNet Wang Wednesday, January 4, 2017 2:32 AM
    Tuesday, January 3, 2017 3:40 AM

Answers

  • Hi,

    Finally, I got the solution to read the SP calendar events including recurring events using lists.asmx from C#. Will share the solution, it may be useful for others in future.

    The query worked after including all the below mentioned fields for "QueryOptions"

                 queryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" +
     
                                                       "<DateInUtc>TRUE</DateInUtc><ViewAttributes Scope=\"Recursive\" />" +
     
                                                      "<RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion>" +
     
                                                       "<ExpandRecurrence>True</ExpandRecurrence>"+
     
                                                       "<CalendarDate>"+ Fromdatestring + "</CalendarDate>"+
     
                                                       "<RecurrenceOrderBy>TRUE</RecurrenceOrderBy>"+
     
                                                       "<ViewAttributes Scope=\"RecursiveAll\"/>";

    Also, refer the below article 

    https://blogs.msdn.microsoft.com/navdeepm/2010/03/11/how-to-query-lists-asmx-to-get-the-recurring-events/

    Thanks & Regards,
    Ramesh

    Friday, September 29, 2017 6:16 AM

All replies

  • Hi Ramesh,

    Based on your description, your case more related to SharePoint, I will help move your case to  

    sharepoint 2013development forum for better support.

    Best regards,

    Kristin


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, January 4, 2017 2:31 AM
  • Hi Ramesh,

    Firstly, make a reference to list.asmx:

    We can set the query like below to get the recurring events:

        const string listName = "TestList";
        var client = new ListServiceProxy.ListsSoapClient();
        var query = new XElement("Query", "<Where><DateRangesOverlap><FieldRef Name="EventDate"/><FieldRef Name="EndDate"/> <FieldRef Name="RecurrenceID"/><Value Type='DateTime'><Year/></Value></DateRangesOverlap></Where>");
        var viewFields = new XElement("ViewFields", "");
        var queryOptions = new XElement("QueryOptions", "<ExpandRecurrence>TRUE</ExpandRecurrence>");
    
    
        var result = client.GetListItems(listName, null, query, viewFields, null, queryOptions, null);
    
        Console.WriteLine(result);

    More information:

    How Get Calendar recurrent events by CSOM from SharePoint 2013.

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Wednesday, January 4, 2017 9:27 AM
  • Hi Jerry,

    Thanks for the update.

    We have tried that approach, but its returning events but recurring events are not getting expanded.

    Please suggest if any other option/solution to expand recurring events.

    Note: We are not allowed to server side object model.

    Thanks
    Ramesh

    Thursday, January 5, 2017 7:19 AM
  • Hi Remesh,

    In SharePoint server object model , we can expand recurring events like below:

    SPSite site = new SPSite("http://sp/sites/test";);
    
    SPWeb web = site.RootWeb;
    
    SPList calendarList = web.Lists["Calendar"];
    
    SPQuery query = new SPQuery();
    
    query.ExpandRecurrence = true;
    
    query.Query = "<Where><DateRangesOverlap><FieldRef
    Name=\"EventDate\" /><FieldRef Name=\"EndDate\" /><FieldRef Name=\"RecurrenceID\"
    /><Value Type=\"DateTime\"><Month /></Value></DateRangesOverlap></Where>";
    
    query.CalendarDate = new DateTime(DateTime.Now.Year,DateTime.Now.Month, 1);
    
    SPListItemCollection calendarItems = calendarList.GetItems(query);
    
    foreach(SPListItem item in calendarItems)
    
    {
    
     Console.WriteLine(item["Title"]+ ": starts "+ item["EventDate"].ToString() +" and ends "+ item["EndDate"].ToString());
    
    }

    Thanks

    Best Regards


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    Thursday, January 5, 2017 7:28 AM
  • Hi Jerry,

    Apologies for the confusion. For our project implementation, server side object model is not applicable. We need to achieve this with either client side object model/REST API or web services (lists.asmx/JQuery SPServices).

    Lists.asmx approach is working as expected if we run it from single html file. But the same code/approach from c# is not working (not expanding the recurring events).

    Please suggest on this.

    Thanks
    Ramesh


    Thursday, January 5, 2017 9:51 AM
  • Hi,

    Finally, I got the solution to read the SP calendar events including recurring events using lists.asmx from C#. Will share the solution, it may be useful for others in future.

    The query worked after including all the below mentioned fields for "QueryOptions"

                 queryOptions.InnerXml = "<IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns>" +
     
                                                       "<DateInUtc>TRUE</DateInUtc><ViewAttributes Scope=\"Recursive\" />" +
     
                                                      "<RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion>" +
     
                                                       "<ExpandRecurrence>True</ExpandRecurrence>"+
     
                                                       "<CalendarDate>"+ Fromdatestring + "</CalendarDate>"+
     
                                                       "<RecurrenceOrderBy>TRUE</RecurrenceOrderBy>"+
     
                                                       "<ViewAttributes Scope=\"RecursiveAll\"/>";

    Also, refer the below article 

    https://blogs.msdn.microsoft.com/navdeepm/2010/03/11/how-to-query-lists-asmx-to-get-the-recurring-events/

    Thanks & Regards,
    Ramesh

    Friday, September 29, 2017 6:16 AM