When you want to look for items on the list or library searching with CAML by URL field you find zero items... although the URL is there.
The typical CAML string is below:
Typical C# code to use SPQuery is:
SPSite oSite = new SPSite("http://moss");
SPWeb oWeb = oSite.OpenWeb();
SPList oList = oWeb.GetListFromUrl("Lists/Links/AllItems.aspx");
SPQuery linksQuery = new SPQuery();
linksQuery.Query = this.txtCAML.Text;
There are few things you may wonder:
1) Should I use <Eq> or <BeginsWith> or <Contains> tag => in my case it turned out BeginsWith works fine (as URL is encoded as "URL, Title" in the field).
2) Shoold the value type be 'Text' or 'Url' => in my case it turned out both are equal.
3) Why the hell I cannot find my items (returns zero)? => it turns out the rules are as follows:
a) IF you look for link that points to the same Sharepoint box THEN you should search with relative URL (so the caml value is just /file.txt
and not http://server/file.txt
b) IF you look for link that points to any other box or even the same box with different port number (e.g. http://server:81/file.txt
) THEN you should use full URL as in the CAML example above.