1
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?

2 Answers 2

2

May be this is the code you are looking for :

var fileName = ''; var fileTitle = ''; _spBodyOnLoadFunctionNames.push("LoadAction"); function LoadAction() { GetFileDetails(fileID); // 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>"; $().SPServices({ operation: "GetListItems", listName: "Project Files", CAMLViewFields: "<ViewFields>" + "<FieldRef Name='FileLeafRef' />"+ "<FieldRef Name='Title' />" + "</ViewFields>", CAMLQuery: query, async: false, completefunc: function (xData, Status) { var xmlDoc = $.parseXML(xData.responseText); //$(xmlDoc).find("z\\:row").each(function(){ $(xmlDoc).find("[nodeName='z:row']").each(function(){ temp_fileName = $(this).attr("ows_FileLeafRef"); temp_title = $(this).attr("ows_Title"); }); } }); fileName = temp_fileName == '' ? '': temp_fileName.split(';#')[1]; fileTitle = temp_title; } 
0
1

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

3
  • thank you for your time and consideration, but i need to get the url of the particular document by using jquery. how would i ?? Commented Jul 9, 2013 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. Commented Jul 9, 2013 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));.) Commented Mar 21, 2019 at 22:47

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.