ChallengeYou are working on a Task List which contains creation dates of various months. You need to search and find the tasks of the current month. How to achieve this using CAML at Client Object Model? DataThe following is the data for the Task List:Note: The test application contains a Create Data button to generate the list & data for you. Please ensure you are running on a test SharePoint server.Using the ApplicationYou can download and run the attached source code.The buttons perform the following:
CAML QueryThe following is the CAML query for specifying the dates:query.ViewXml = @"<View>" +"<Query>" + "<Where><And>" + "<Geq>" + "<FieldRef Name='DueDate'/>" + "<Value Type='DateTime' IncludeTimeValue='FALSE'>" + startDateFx + "</Value>" + "</Geq>" + "<Leq>" + "<FieldRef Name='DueDate'/>" + "<Value Type='DateTime' IncludeTimeValue='FALSE'>" + endDatFx + "</Value>" + "</Leq>" + "</And></Where>" +"</Query>" +"</View>";FiltersWe are using Geq (Greater than or Equal) and Leq (Less than or Equal) filters in the query.Date FormatPlease note that the dates are formatted as below:
string startDateFx = startDate.ToString("yyyy-MM-ddTHH:mm:ssZ");string endDatFx = endDate.ToString("yyyy-MM-ddTHH:mm:ssZ");Please note that in the Server Object Model we can use the SPUtility.CreateISO8601DateTimeFromSystemDateTime method to achieve the same. CAML Query BuilderYou can validate your CAML queries using the following tool:U2U CAML Query Builderhttp://www.u2u.net/res/Tools/CamlQueryBuilder.aspxExecuting the ApplicationOn executing the application and clicking the buttons we will see the results below:The first task list displays all the items and the second task list displays on the items in the current month based on the Due Date column.Referenceshttp://msdn.microsoft.com/en-us/library/microsoft.sharepoint.utilities.sputility_methods.aspxhttp://www.u2u.net/res/Tools/CamlQueryBuilder.aspxSummaryIn this article we have explored the solution for handling date in client object model. I hope the code could help you in a scenario involving client object model. The attachment contains the code we have discussed.
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: