foreach (SPListItem item in listitems)
    String value = item.File.Name;    

The above sever side code shows how to retrieve the name of a document which is saved in a SharePoint document library by using item.File.Name. I have done this completely, but how do I do the same thing using the Client Object Model. What should I use instead of item.File.Name?


May be this is the code you are looking for :

var fileName = '';  
var fileTitle = '';
function LoadAction() 

// File Title   
if(fileTitle != undefined)
    document.getElementById("txtTitle").innerHTML = fileTitle;
// File Name
if(fileName != undefined)
    document.getElementById("txtName").innerHTML = fileName;    

function GetFileDetails(itemID)
    var temp_fileName = '';
    var temp_title ='';
    var query = "<Query><Where><Eq><FieldRef Name='ID' /><Value Type='Counter'>" + itemID + "</Value></Eq></Where></Query>";
        operation: "GetListItems",
        listName: "Project Files",
        CAMLViewFields: "<ViewFields>" +
                            "<FieldRef Name='FileLeafRef' />"+
                            "<FieldRef Name='Title' />" +
        CAMLQuery: query,
        async: false,
        completefunc: function (xData, Status) {
            var xmlDoc = $.parseXML(xData.responseText);
                temp_fileName = $(this).attr("ows_FileLeafRef");
                temp_title = $(this).attr("ows_Title");    

    fileName = temp_fileName == '' ? '': temp_fileName.split(';#')[1];
    fileTitle = temp_title; 

You can still use item.File.Name. The difference being that this list item is a Microsoft.SharePoint.Client.ListItem type, and the .File here is Microsoft.SharePoint.Client.File.

If you're looking to learn more about how to use the CSOM, this should help get you started:

How to: Complete basic operations using SharePoint 2013 client library code

  • thank you for your time and consideration, but i need to get the url of the particular document by using jquery. how would i ??
    – Nera
    Jul 9 '13 at 13:58
  • 1
    If you have another question, you should post it as a new thread. Please refer to sharepoint.stackexchange.com/help/how-to-ask for further clarification. Jul 9 '13 at 14:38
  • Thanks, that worked for me. (FYI, you will have to load the File and File.Name property but they can all be retrieved in the same call; e.g. ctx.Load(items, i => i.Include(x => x.DisplayName, x => x.File, x => x.File.Name));.) Mar 21 '19 at 22:47

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.