Monday, October 18, 2010

How is the Attachment column worked in CAML query?

It took me a few minutes to fix this issue.

SharePoint did not allow you filter the value of attachment column with another value except for "Yes" or "No". But when you bind data into a gridview with filtering option is ON, user still can type or filter this column with another value, for example: Greater than "5" or Less Than "OK"

1) Greater Than "5" Our CAML query is

Result: No record is displayed. That would be nice. But when you change Less Than "5", it would be:

You know, with Attachments column, if the item has an attachment, its value is 1 and otherwise is 0. So, the CAML query is less than "5" matched with items which have both an attachment and none. That's very funny.

2) Less Than "OK"

I really dont know how the SharePoint parsed this value, but it will show data with items which has no attachment.

Conclusion: When you want to return "No record" if user filters with the value different from "Yes" / "No" or "1" / "0" the value in CAML query must be "." (dot) 

Yeap. It worked for me now.

1 comment:

Anonymous said...

I liked the article, but some disagree