Click here to Skip to main content
15,904,351 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I have a calendar in sharepoint,now i want get events of between two date..
but My code does not work!


DateTime startDate = faDatePicker1.SelectedDateTime;
 DateTime EndDate = faDatePicker2.SelectedDateTime;

XML
using (ClientContext context = new ClientContext(siteUrl))
           {
               context.Credentials = new NetworkCredential(Properties.Settings.Default.Username, "123", "mesbahsoft.local");
               List oList = context.Web.Lists.GetByTitle("Vacation");

               CamlQuery camlQuery = new CamlQuery();
               camlQuery.ViewXml = "<query><Where><Geq><FieldRef Name='EventDate' /><Value Type='DateTime'>" + startDate + "</Value>" +
               "</Geq><Leq><FieldRef Name='EventDate' /><Value Type='DateTime'>" + EndDate + "</Value></Leq><And><Geq><FieldRef Name='EndDate' /><Value Type='DateTime'>" + startDate + "</Value></Geq><Leq><FieldRef Name='EndDate' /><Value Type='DateTime'>" + EndDate + "</Value></Leq></Where></query>"; 
               ListItemCollection collListItem = oList.GetItems(camlQuery);

               context.Load(collListItem);

               
                   context.ExecuteQuery();
}
Posted
Updated 10-Nov-14 20:52pm
v3

1 solution

I consider it rude that you are asking the same question all over different forums, just to check who gives the cooked code first.

http://sharepoint.stackexchange.com/questions/120743/get-a-list-of-events-that-are-between-two-date[^]

Apart from that CAML isn't rocket science. Have you tried to debug?
What are the results you get if you remove the filter from CAML? Is the format of startdate and enddate you are passing is correct?

There are so many variables but the best person who can really help is you yourself.
 
Share this answer
 
Comments
je30ca 11-Nov-14 3:55am    
You're right.sorry
I deleted my post in stack... :(
But thanks for the answer...
BillWoodruff 11-Nov-14 4:23am    
My vote of #1: Is it really a bad thing that someone posts the same question here and on other sites like StackOverFlow ? Does that really mean they are "rude" ? Note that I do consider people who don't respond to requests for clarification, or helpful suggestions to use the debugger, etc., as either "slow-learners" or "non-learners."

imho, this kind of response, posted as a "solution" does not add value to CodeProject.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900