tags:

views:

563

answers:

1

My original question here answers how to check if an item exists in a list, but this doesn't work for items in sub folders in the list.

How can I check if an item exists, regardless of what subfolder its stored in?

Failing this, how can I check if an item exists , even if this means somehow passing the subfolder value to the query somehow?

Following code works, but will not look in subfolders:

private bool attachmentLinkItemDoesntExist(string attachmentName)
{
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<Document><Query><Where><Contains><FieldRef Name=\"Title\" /><Value Type=\"Text\">" +  this.downloadedMessageID + "_" + attachmentName + "</Value></Contains></Where></Query><ViewFields /><QueryOptions /></Document>");
    XmlNode listQuery = doc.SelectSingleNode("//Query");
    XmlNode listViewFields = doc.SelectSingleNode("//ViewFields");
    XmlNode listQueryOptions = doc.SelectSingleNode("//QueryOptions");
    XmlNode items = this.wsLists.GetListItems(this.AttachmentsListName , string.Empty, listQuery, listViewFields, string.Empty, listQueryOptions, null);
    if (items.ChildNodes[1].Attributes["ItemCount"].Value == "0")
    {
        return true;
    }
    else
    {
        return false;
    }
}
A: 

You need to set the Scope to Recursive

You can do this using the object model SPQuery.ViewAttributes

query.ViewAttributes = "Scope=\"Recursive\"";

Looks like you are using the web service GetListItems so you would pass this param in QueryOptions

<QueryOptions>
   <ViewAttributes Scope="Recursive" />
</QueryOptions>
Ryan