CAML > get an item by it's URL
Asked Answered
C

1

6

Should this CAML be working. (I tried it with u2u and it does not display the URL column.) I get this error. {System.ApplicationException} = {"One or more field types are not installed properly. Go to the list settings page to delete these fields."}

<Where>
 <Eq>
     <FieldRef Name='URL' />
     <Value Type='URL'>/path/HR Policy.docx</Value>
 </Eq>
</Where>
Closefisted answered 14/3, 2011 at 15:39 Comment(2)
Now using <Contains> instead of <where> and working.Closefisted
The URL field will have the display text also stored in it, so this is why you need the Contains node.Paraselene
K
6

Querying for a Document in a Document Library

Looks like you are trying to find a document in a document library using CAML. You can do this by using the hidden column named "FileRef":

<Where><Eq><FieldRef Name="FileRef"/><Value Type="Url">sites/SiteCollection/SubSite/Site Documents/Excel Report.xls</Value></Eq></Where>

Note: Do not include the server name or beginning /.

Querying for a document or list item with a URL field

The following examples assuming you have a list or library setup with a URL column named "My Document".

The link is to a document that is hosted on the sharepoint server (do not need server name):

<Where><Eq><FieldRef Name="My_x0020_Document"/><Value Type="URL">/sites/subsite/Site%20Documents/Excel%20Report.xls</Value></Eq></Where>

The link is an absolute URL to something not on the server... for example http://www.google.com:

<Where><Eq><FieldRef Name="My_x0020_Document"/><Value Type="URL">http://www.google.com</Value></Eq></Where>
Klopstock answered 14/3, 2011 at 20:53 Comment(9)
@Kit Menke: I tried this as well (including yours) but same field not installed error <Where><Contains><FieldRef Name='URL'/><Value Type='URL'>/sites/SiteCol/subsite/Shared Documents/March Excel Report.xls</Value></Contains></Where>Closefisted
@Mina Kumari: I've updated the answer to include a query for a document in a document library which I think is what you're after.Klopstock
@Kit Menke: I am not getting that error with this code. I should see one file but no record is returned with the query. <Where><Eq><FieldRef Name="FileRef"/><Value Type="Url">sites/SiteCollection/SubSite/Site Documents/Excel Report.xls</Value></Eq></Where>Closefisted
@Mina Kumari: What's the path of your document and did you put that into the query? Can you show the exact query you are trying?Klopstock
<Where><Eq><FieldRef Name='FileRef'/><Value Type='Url'>sites/gatorade/Shared Documents 5/Sales Folder/Team_lists.txt</Value></Eq></Where> I put this in u2u tool. havnt tried in the winform app.Closefisted
Ah... are you using oQuery.ViewAttributes = "Scope=\"Recursive\"";? msdn.microsoft.com/en-us/library/… Since it is in a folder you'll need the recursive attribute.Klopstock
@Kit Menke, I do have the recursive in the winform code. I tried your modified in u2u and i didnt see an option for recursive in u2u. I will try the modified in winform and let you know. ThanksClosefisted
@Kit Menke. It finally worked. Thanks for sticking with me and resolve this issue. THANKS A LOT...... MINAClosefisted
Hey it doesnt work for me when I write - <Where><Eq><FieldRef Name="FileRef"/><Value Type="Url">/Sites/ASCAteam/GlobalBrandPlan/MigrationSpec-Rev-3rd_031915.xlsx</Value></Eq></Where> but it works for a file which is directly under documents - <Where><Eq><FieldRef Name="FileRef"/><Value Type="Url">Documents/SharePointDeleteListItemExample.properties</Value></Eq></Where>Reciprocity

© 2022 - 2024 — McMap. All rights reserved.