I have created one SharePoint Hosted App. Its Url is Like: https://a.sharepoint.com/ sites/SharePointAddIns/CreateZip19/Pages/ Default.aspx? SPHostUrl= SPLanguage=en-US&SPClientTag=0& SPProductNumber=16%2E0%2E5806%2E1207& SPAppWebUrl=2FCreateZip19& SPListItemId=11,14& SPListId={33C66D4B-48C2-4A5D-98BF-4D82FEB5CE0D}

I get SPListItemId and SPListId in App.Js

    var clientContext, hostweburl, parentContext, parentWeb, selectedItems, itemIds, listId;
clientContext = new SP.ClientContext.get_current();
hostweburl = decodeURIComponent(GetUrlKeyValue("SPHostUrl"));
listId = decodeURIComponent(GetUrlKeyValue("SPListId"));
itemIds = decodeURIComponent(GetUrlKeyValue("SPListItemId")).split(',');

Now Question is : How can I get My document Title name and Url using listId and ItemIds I have tried this.

var oList = clientContext.get_web().get_lists().getById(Listitemid);
oListItem = oList.getItemById(itemid);
var file = oListItem.get_file();
var filename = file.get_name();

But I didnot get file name.

How can I get filename of all selected file using SPListitemId and SPListId ?

1 Answer 1


In SharePoint Hosted App to get Information of File and its path we can use REST API. I Used Rest call for it.

var context = SP.ClientContext.get_current();
var user = context.get_web().get_currentUser();
var listid = decodeURIComponent(GetUrlKeyValue("SPListId")).slice(1, -1);
var hostweburl = decodeURIComponent(GetUrlKeyValue("SPHostUrl"));
var appweburl = decodeURIComponent(GetUrlKeyValue("SPAppWebUrl"));
var itemIds = decodeURIComponent(GetUrlKeyValue("SPListItemId")).split(',');

Pass ListItemId to your function

function getListVersioningInfo(itemIdd) {


        url: window.location.protocol + "//" + window.location.host + _spPageContextInfo.siteServerRelativeUrl + "/_api/web/lists('"+listid+"')/items(" + itemIdd + ")?$select=*&$expand=File",

        method: "GET",
        async: false,

        headers: {

            "Accept": "application/json; odata=verbose"


        success: function (data) {

            var fileName = data.d.File.Name;
            var filePath = data.d.File.ServerRelativeUrl;


        error: function (data) {





Using this Rest Call you will get FileName and FilePath

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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