Forum Discussion
CAML Query to filter library not working as expected
- Aug 11, 2022
Dear All, I used below format and it worked, thanks for your support... I am sharing below CAML code...
string Iso8601Today = XmlConvert.ToString(DateTime.Now, XmlDateTimeSerializationMode.Local);
_query.ViewXml = "<View><Query>" +
"<Where>" +"<Leq>" +
"<FieldRef Name='testDate'/>" +
"<Value IncludeTimeValue='FALSE' Type='DateTime'>"+Iso8601Today+"</Value>" +
"</Leq>" +
"</Where>" +
"<OrderBy><FieldRef Name ='Created' Ascending = 'True' /></OrderBy></Query></View>";I got the required result, please add your comment for more optimization ...
regards
Badar
You should use two condition in AND tag and here you need only one AND tag according to your requirement. Please use below query and it should work
<View>
<Query>
<Where>
<And>
<Eq>
<FieldRef Name='Description0' />
<Value Type='Text'>You Value</Value>
</Eq>
<Geq>
<FieldRef Name='Modified' />
<Value IncludeTimeValue='FALSE' Type='DateTime'>
<Now />
</Value>
</Geq>
</And>
</Where>
<OrderBy>
<FieldRef Name='Modified' Ascending='True' />
</OrderBy>
</Query>
</View>
CAML Query Documentation: https://docs.microsoft.com/en-us/sharepoint/dev/schema/query-schema
Hope it will help to you.
- badar_000Aug 08, 2022Copper Contributor
I tried below after your comments but result is same , thanks for your reply..
_query.Query = "<View><Query>" +
"<Where><And>" +
"<Eq><FieldRef Name='Description0' /><Value Type='Text'>" + myParam.ToString() + "</Value></Eq>" +
"<Geq><FieldRef Name='Modified'/><Value IncludeTimeValue='FALSE' Type='DateTime'><Now /></Value></Geq>" +
"</And>" +
"</Where>" +
"<OrderBy><FieldRef Name ='Created' Ascending = 'True' /></OrderBy></Query></View>";- kalpeshvaghelaAug 08, 2022Iron Contributor
What is the type of Description0 field? if it's multiline of text then use below query.
<View> <Query> <Where> <And> <Eq> <FieldRef Name='Description0' /> <Value Type='Note'>You Value</Value> </Eq> <Geq> <FieldRef Name='Modified' /> <Value IncludeTimeValue='FALSE' Type='DateTime'> <Now /> </Value> </Geq> </And> </Where> <OrderBy> <FieldRef Name='Modified' Ascending='True' /> </OrderBy> </Query> </View>- badar_000Aug 08, 2022Copper Contributor