We’re rewarding the question askers & reputations are being recalculated! Read more.
1 of 2

Can't get Document Library CAML Query to work

I have a document library with 5 content types. Each content type has the same lookup on another list. I need a caml query that checks if a document with the same content type and lookup value exists in a given folder, excluding the item that has just been added.

Here is my logic (I use this logic in an ItemUpdated Event for the document library):

var ctId = listItem.ContentTypeId;
var customer = listItem[Fields.customersID] as SPFieldLookupValueCollection;
var project = new SPFieldLookupValue(listItem[Fields.miscellaneousProjectRecordID] as String);
var id = listItem.ID;

var projectsubfolder = list.RootFolder.SubFolders[project.LookupValue];

var query = new SPQuery
    Folder = projectsubfolder,
    Query = "<Query>" +
                "<Where>" +
                    "<And>" +
                        "<And>" +
                            "<Neq>" +
                                "<FieldRef Name=\"ID\" />" +
                                "<Value Type=\"Counter\">" + id + "</Value>" +
                            "</Neq>" +
                            "<Eq>" +
                                "<FieldRef Name=\"Customers\" LookupId=\"TRUE\" />" +
                                "<Value Type=\"LookupMulti\">" + customer[0].LookupId + "</Value>" +
                            "</Eq>" +
                        "</And>" +
                        "<Eq>" +
                            "<FieldRef Name=\"ContentTypeId\" />" +
                            "<Value Type=\"ContentTypeId\">" + listItem.ContentTypeId + "</Value>" +
                        "</Eq>" +
                    "</And>" +
                "</Where>" +

var items = list.GetItems(query);

return items;

However, this also returns the item which has been added. In other words, the part doesn't seem to work. Am I doing something wrong here?