views:

43

answers:

1

I need to select a single value from a SharePoint list based on a field value. The type of the field is LinkFieldValue. How should I write the CAML query?

When I select the items with an empty query, I receive all the items in the list as expected.

When I add constraints to the query, it returns an empty result. I have tried constructing the query as follows:

string.Format("<Where><Eq><FieldRef Name=\"PollInstancePoll\" /><Value "
+"Type=\"Text\">{0}</Value></Eq></Where>",
new LinkFieldValue { NavigateUrl = "/az/Lists/Polls/DispForm.aspx?ID=1",
Text = "example poll" });

which results in the following query text:

<Where><Eq><FieldRef Name="PollInstancePoll" />
<Value Type="Text"><a href="/az/Lists/Polls/DispForm.aspx?ID=1">example poll</a></Value>
</Eq></Where>
+1  A: 

I have solved my problem with the following query:

new SPQuery
{
    Query =
        CAML.Where(
            CAML.And(
                CAML.Contains(
                    CAML.FieldRef("PollInstancePoll"),
                    CAML.Value(pollPath)),
                CAML.Contains(
                    CAML.FieldRef("PollInstancePage"),
                    CAML.Value(pagePath))))
};

Essentially I am checking only the URL part of the Link field, and providing the value for comparison as Type="Text". It is important to remember that SharePoint stores the values in database always as server-relative URLs.

skolima
+1 For introducing me to CAML.NET
Janis Veinbergs