Caml query on URL field (stupid design)

Source: Internet
Author: User
Document directory
  • Answers
  • All replies
  • Hello,

    I am trying to write a custom search query using caml on a list which contains a URL field.

    The caml query contains a where clause on the URL field. what I have noticed is that when the URL field is used in the WHERE clause it does not return any results back. maybe my caml query is wrong ??

    Any help wocould be appreciated.

    Here is the caml query snippet:

    <Where>

    <Beginswith>

    <Fieldref name = 'url'/>

    <Value type = 'text'> http: // moss12/Client1 </value>

    </Beginswith>

    </Where>

    Now, I have also tried changing the value type to URL...

    <Where>

    <Beginswith>

    <Fieldref name = 'url'/>

    <Value type = 'url'> http: // moss12/Client1 </value>

    </Beginswith>

    </Where>

    I have also tried using <contains>, <EQ> conditions, but no results. Has anyone tried writing caml queries on URL field?

     
Answers
  • Friday, January 04,200 pm

    M. blumenthalmagenic (partner)

    30 points 2

    Sign in to vote

    I recently needed to see if an URL was in an splist, And what I ended up doing was this:

    1. Create a string variable to hold the tail end of the url I am looking. so if I am looking forhttp: // server/managedpath/spweborsitecollectionname, I wocould put "/managedpath/spweborsitecollectionname" in the urltail string variable.
    2. Do my spquery to match against the urltail instead of the URL, my caml wowould look like this:

    <Where>

    <Beginswith>

    <Fieldref name = 'url'/>

    <Value type = 'url'>/managedpath/spweborsitecollectionname </value>

    </Beginswith>

    </Where>

     

    3. When I get my results back, convert each one to a string and see if it contains the full URL (http: // server/managedpath/spweborsitecollectionname ).

    Hope that helps!

    -- M. blumentha

    • Reply
    •  

    • Quote
     
All replies
  • Wednesday, September 26,200 7 pm

    Steve Curran mvpknowledgelake (partner, MVP)

    29,755 points 0

    Sign in to vote

    Change your type to URL

     

    <Value type = 'url'> http: // moss12/Client1 </value>

     

     
    • Reply
    •  

    • Quote
     
  • Thursday, September 27,200 AM

    Pritam dahake

    90 points 0

    Sign in to vote

    In the 2nd caml code snippet I have, I did try with value type of 'url'... but it doesnt return any results ..

    Can you confirm that you are able to use URL field in your caml query?

     

    Thanks

     
    • Reply
    •  

    • Quote
     
  • Thursday, September 27,200 7 AM

    Steve Curran mvpknowledgelake (partner, MVP)

    29,755 points 0

    Sign in to voteyes

     

     
    • Reply
    •  

    • Quote
     
  • Thursday, September 27,200 pm

    Pritam dahake

    90 points 0

    Sign in to vote

    Smc750,

    Below is the code snippet I am actually using in my application and it is not returning any results back.

    The "sites" list has a column of Type hyperlink called "url" with internal name as "siteurl ". the list has right now two items in it, with URLs http: // moss12/Client1 and http: // moss12/Client2. using this query I was expecting to get both the items back.

     

    Do you see anything wrong with the code here? I have tried using fieldref name = 'url' as well as fieldref name = "siteurl'... both dont return any results back !!!

     

     

    Spweb = spcontext. Current. Web;

    String squery = "<where> <beginswith> <fieldref name = 'url'/> <value type = 'url'> HTTP: // moss12/client </value> </beginswith> </where> ";

    String slist = "sites ";

    Splist = spweb. Lists [slist];

    Spquery query = new spquery ();

    Query. query = squery;

    Splistitemcollection items = splist. getitems (query );

     
    • Reply
    •  

    • Quote
     
  • Thursday, September 27,200 pm

    Steve Curran mvpknowledgelake (partner, MVP)

    29,755 points 0

    Sign in to votenothing wrong here. cocould be security. check to make sure the user executing query has read rights to the items in question.

     

     
    • Reply
    •  

    • Quote
     
  • Thursday, September 27,200 pm

    Pritam dahake

    90 points 0

    Sign in to vote

    The code is in development running on my machine...

    I am the machine admin... the SharePoint service is running under my account... so there is no security issue here...

     

     
    • Reply
    •  

    • Quote
     
  • Friday, October 05,200 pm

    Robert L. bogue [MVP] Thor projects LLC (partner, MVP)

    25 points 0

    Sign in to vote

     

    The problem is likely that moss12 is the name of your Sharepoint Server. sharePoint strips the server name for relative URLs before storing them in the DB so when caml does the query it needs to be just the relative path.

     
    • Reply
    •  

    • Quote
     
  • Tuesday, October 09,200 pm

    Dan keelingslalom Consulting (partner)

    1,530 points 0

    Sign in to vote

    Download and use the u2u tool, you can get test data back from an order by query, and then see in plain text what the values of the URL field look like. then change as needed. link is here

     
    • Reply
    •  

    • Quote
     
  • Monday, October 22,200 pm

    Kjapsbufdir

    20 points 0

    Sign in to vote

     

    Did you find a solution to this issue? I have the exact same problem. I have used the caml Query Builder (u2u) to examine the URL field, and it looks like this

     

    Http: // server/myweb, http: // server/myweb

     

    This is driving me nuts.

     
    • Reply
    •  

    • Quote
     
  • Monday, October 22,200 7 pm

    Steve Curran mvpknowledgelake (partner, MVP)

    29,755 points 0

    Sign in to vote

    This whole issue cocould be related to a Microsoft Bug in the spquery and spquerysitedataquery classes. you can find out more here. this bug is not due to be fixed until SP2. I have seen no results come back for this reason reset times.

     

    Http://www.sharepointblogs.com/smc750/archive/2007/07/24/spsitedataquery-limited-to-10-document-libraries-or-lists.aspx

     

     
    • Reply
    •  

    • Quote
     
  • Friday, January 04,200 pm

    M. blumenthalmagenic (partner)

    30 points 2

    Sign in to vote

    I recently needed to see if an URL was in an splist, And what I ended up doing was this:

    1. Create a string variable to hold the tail end of the url I am looking. so if I am looking forhttp: // server/managedpath/spweborsitecollectionname, I wocould put "/managedpath/spweborsitecollectionname" in the urltail string variable.
    2. Do my spquery to match against the urltail instead of the URL, my caml wowould look like this:

    <Where>

    <Beginswith>

    <Fieldref name = 'url'/>

    <Value type = 'url'>/managedpath/spweborsitecollectionname </value>

    </Beginswith>

    </Where>

     

    3. When I get my results back, convert each one to a string and see if it contains the full URL (http: // server/managedpath/spweborsitecollectionname ).

     

     

    Hope that helps!

    -- M. Blumenthal

     

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.