Working with SharePoint and CAML can be a pain, but in VB.NET it's actually quite beautiful using the XML Literals feature.

Here's a query to get all web page documents in a SharePoint list that have been modified since some date.

Dim query = _
<Query>
    <Where>
        <And>
            <Gt>
                <FieldRef Name="Modified"/>
                <Value IncludeTimeValue="TRUE" Type="DateTime"><%= lastSyncDate.GetValueOrDefault(DateTime.MinValue).ToString("yyyy-MM-ddTHH:mm:ssZ") %></Value>
            </Gt>
            <And>
                <Eq>
                    <FieldRef Name="FSObjType"/>
                    <Value Type="Lookup">0</Value>
                </Eq>
                <Eq>
                    <FieldRef Name="DocIcon"/>
                    <Value Type="Lookup">aspx</Value>
                </Eq>
            </And>
        </And>
    </Where>
</Query>
 

The same query in C# (using Linq to XML) looks like this:

var query =
    new XElement("Query",
        new XElement("Where",
            new XElement("And",
                new XElement("Gt",
                    new XElement("FieldRef",
                        new XAttribute("Name", "Modified")
                    ),
                    new XElement("Value",
                        new XAttribute("IncludeTimeValue", "TRUE"),
                        new XAttribute("Type", "DateTime"),
                        DateTime.Now.ToString()
                    )
                ),
                new XElement("And",
                    new XElement("Eq",
                        new XElement("FieldRef",
                            new XAttribute("Name", "FSObjType")
                        ),
                        new XElement("Value",
                            new XAttribute("Type", "Lookup"),
                            0
                        )
                    ),
                    new XElement("Eq",
                        new XElement("FieldRef",
                            new XAttribute("Name", "DocIcon")
                        ),
                        new XElement("Value",
                            new XAttribute("Type", "Lookup"),
                            "aspx"
                        )
                    )
                )
            )
        )
    );
 

Comment