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 a problem with a CAML Query for a Sharepoint Online(Office365) Calendar. I try to get all Calendar Appointments between two dates. Here is my code:

        private void getFreeDays()
        {
        List urlaubskalender = clientContext.Web.Lists.GetByTitle("Urlaubskalender");

        DateTime startDate = Convert.ToDateTime(dpEventDate.SelectedDate);
        DateTime endDate = Convert.ToDateTime(dpEndDate.SelectedDate);

        CamlQuery getDatesQuery =new CamlQuery();
        getDatesQuery.ViewXml = "<Query>"+
                                    "<Where>"+
                                        "<And>"+
                                            "<Geq>"+
                                                "<FieldRef Name='EventDate' />"+
                                                    "<Value Type='DateTime'>"+startDate+"</Value>"+
                                            "</Geq>"+
                                            "<Leq>"+
                                                "<FieldRef Name='EndDate' />"+
                                                    "<Value Type='DateTime'>"+endDate+"</Value>"+
                                            "</Leq>"+
                                        "</And>"+
                                    "</Where>"+
                                "</Query>";

        eventCollection = urlaubskalender.GetItems(getDatesQuery);
        clientContext.Load(eventCollection);

        clientContext.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(onQSGetEvents), null);
        }

The Problem is that I get appointments from 01.01.2013 when I select 01.02.2013 as EventDate and 08.02.2013 as EndDate. The appointment is a reccurent one, maybe this is the cause of the problem? I tried to find some informations to create a CAML Query without recurring appointment but i couldn't found something. Maybe the failure is something total different...

I hope someone can help me...and sorry for my bad english, i gave my best ;)

share|improve this question
add comment

2 Answers 2

I have solved the problem. I can change the format of the DateTime variable with startDate.ToString("yyyy-MM-ddTHH:mm:ssZ")

I have build the query with the U2U Query Builder (great tool!) here is the query if someone is interested in thisgetDatesQuery.ViewXml = "<Query>" + "<Where>" + "<And>" + "<Eq>" + "<FieldRef Name='fRecurrence' />" + "<Value Type='Recurrence'>false</Value>" + "</Eq>" + "<And>" + "<Leq>" + "<FieldRef Name='EventDate' />" + "<Value IncludeTimeValue='TRUE' Type='DateTime'>" + startDate.ToString("yyyy-MM-ddTHH:mm:ssZ") + "</Value>" + "</Leq>" + "<Geq>" + "<FieldRef Name='EndDate' />" + "<Value IncludeTimeValue='TRUE' Type='DateTime'>" + endDate.ToString("yyyy-MM-ddTHH:mm:ssZ") + "</Value>" + "</Geq>" + "</And>" + "</And>" + "</Where>" + "<OrderBy>" + "<FieldRef Name='EventDate' Ascending='True' />" + "</OrderBy>" + "</Query>";

share|improve this answer
add comment

You need to use the SPUtility.CreateISO8601DateTimeFromSystemDateTime() method to get your date times in the proper format.

share|improve this answer
    
Thanks for your answer. I use the Client Object Model. There is just a Class called ClientUtility ( msdn.microsoft.com/en-us/library/ee538654.aspx ). It has no method CreateISO8601DateTimeFromSystemDateTime() or something like this. Do you know a workaround for my issue? –  Alexander Feb 5 '13 at 10:18
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.