I am trying to remove an attachment from a list of attachments using the CAML, however; when I do the query it always returns both of my files. I only need to get the file of the current one using the passed in value as the parameter.
SP.List list = context.Web.Lists.GetByTitle("TempAttachments");
// Query
SP.CamlQuery query = new SP.CamlQuery();
query.ViewXml =
"<Query><Where><Or>"
+ "<BeginsWith>"
// Job Note Matches
+ "<FieldRef Name=\"FileRef\"/>"
+ "<Value Type=\"Text\"/>" + ID + "_</Value>"
+ "</BeginsWith>"
// OR Date Modified is older than one day.
+ "<Lt>"
+ "<FieldRef Name=\"Modified\"/>"
+ "<Value Type=\"DateTime\"/><Today OffsetDays=\"-1\" /></Value>"
+ "</Lt>"
+ "</Or>"
+ "</Where></Query>";
Could the Beginswith tag be the problem?
Your CAML query needs to be wrapped in a
View
element when seeting theViewXml
.Your
Value
tags are both malformed; you're closing the element in the opening tag, meaning you have malformed XML.Your query has an underscore at the end of the value you specify for the file name, but in the examples you mentioned in comments, your actual files don't have one, so that shouldn't be there.
So your query can now become: