CAML and document library URL

Posted on 2012-09-19
Last Modified: 2012-09-20
Hello. Is it possible to use CAML to get url of document in library?  I would like to create a web part that shows hyperlinks to items in library. I played with CamlDesigner but I were not able get url to list item:


Open in new window

I could do something like that:

string url = basicurl+FileLeafRef (seem to be a file name with extensions). 

Open in new window

But still I am little bit confused, as I am able to get url to the list item if I choose to use SharePoint web services (ows_EncodedAbsUrl). Am I doing something wrong? Perhaps this is issue related to CamlDesigner.
Question by:tolppa
    LVL 44

    Accepted Solution

    your CAML should include this in the ViewFields:
    <FieldRef Name="EncodedAbsUrl" />

    If you want to code it in C# / web part code then use this
    string sQuery = @"<Query><Where><IsNotNull><FieldRef Name=""Title"" /></IsNotNull></Where></Query>";
    string sViewFields = @"<FieldRef Name=""Title"" /><FieldRef Name=""EncodedAbsUrl"" />";

    Open in new window

    and set it to your SPQuery object.

    I used this tool
    which could also generate the C# code for the query.

    LVL 1

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    I used to be SharePoint evangelist in our company, so my Outlook always full of questions about how to do this, or where I can find that. One day I found such an email with the following question: "how to attach 3-State workflow (one of the workflow…
    Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    This video discusses moving either the default database or any database to a new volume.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now