1

I am using SPServices GetListItems method to retrieve items from a document library and show them on the screen. So far I am able to get the Title of the items and append them to a div on the page. The problem is when I try to get the URL of the item, it returns Undefined. Here is the code I am using:

$().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "News",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /><FieldRef Name='Url' /></ViewFields>",
    completefunc: function (xData, Status) {
        $(xData.responseXML).SPFilterNode("z:row").each(function() {
            var href = ($(this).attr("ows_Url"));
            var title = ($(this).attr("ows_Title"));
            var liHtml = "<p><a href='" + href + "'>" + title + "</a></p>";
            $("#content").append(liHtml);
        });
    }
});

After researching the issue myself, I read that ows_Url is a managed property and I think it may not be retrievable? Is this correct? If this is the case, how can I get this URL attribute?

2

In a document library, you'd want to use the ows_FileRef field to pull the URL of the file. This will get you a value like, /managedpath/site/library/filename.jpg, which is what I think you're after here.

1

Document library does not have any URL column unless you create custom one. I think your requirement is to get the the URL and Title of documents. In document library there is a hidden column named FileRef. It stores document's relative path like

/yourSiteUrl/YourLibraryNam/FileName.Extension

So your CAMLViewFields should look like following

"<ViewFields>
    <FieldRef Name='Title' />
    <FieldRef Name='FileRef' />
</ViewFields>"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.