2

Value does not fall within the expected range.

  function getFileProperties(url,success,error) {
   var ctx = SP.ClientContext.get_current(); 
   var relUrl = url.replace(_spPageContextInfo.siteAbsoluteUrl,'');  //convert to relative url
   var file = ctx.get_web().getFileByServerRelativeUrl(relUrl);   //get file
   ctx.load(file,"'ListItemAllFields'"); 

   ctx.executeQueryAsync(
      function () {
         success(file);
      }, 
      error
   );
}

getFileProperties('https://unileverdev.sharepoint.com/sites/Test%20Documents/GLOBAL pnp 2017-02-27.css',
  function(file){
     var listItem = file.get_listItemAllFields();
     console.log(listItem);
  },
  function(sender,args){
      console.log(args.get_message());
  });
1
  • I am getting error Value does not fall within the expected range
    – sachin
    Commented Mar 7, 2017 at 8:40

2 Answers 2

1
function getFileProperties(url,success,error) {

   var ctx = SP.ClientContext.get_current(); 
   //var relUrl = url.replace(_spPageContextInfo.siteAbsoluteUrl,'');  //convert to relative url
   var file = ctx.get_web().getFileByUrl(url);   //get file
   ctx.load(file); 

   ctx.executeQueryAsync(
      function () {
         success(file);
      }, 
      error
   );
}
getFileProperties('https://unileverdev.sharepoint.com/sites/Test_Vishwa/Test%20Documents/GLOBAL pnp 2017-02-27.css',
  function(file){
     var listItem = file.get_listItemAllFields();
     var ctx = SP.ClientContext.get_current();
     ctx.load(listItem);
     ctx.executeQueryAsync(
      function () {
         listItem.get_item('Title')
         console.log(listItem)
      }, 
      function(){
        console.log(args.get_message());
      }
   );
     console.log(listItem);
  },
  function(sender,args){
      console.log(args.get_message());
  });
1
  • Update code It works for me
    – sachin
    Commented Mar 7, 2017 at 9:07
0

Please try below code.

 function getFileProperties(url,success,error) {
   var ctx = SP.ClientContext.get_current(); 
   var relUrl = url.replace(_spPageContextInfo.siteAbsoluteUrl,'');  //convert to relative url
   var file = ctx.get_web().getFileByServerRelativeUrl(relUrl);   //get file
   ctx.load(file,"'ListItemAllFields'"); 

   ctx.executeQueryAsync(
      function () {
         success(file);
      }, 
      error
   );
}

getFileProperties('/sites/Test%20Documents/GLOBAL pnp 2017-02-27.css',
  function(file){
     var listItem = file.get_listItemAllFields();
     console.log(listItem);
  },
  function(sender,args){
      console.log(args.get_message());
  });

Hope it will works for you.

1
  • It is giving error ListItemAllFields not defined
    – sachin
    Commented Mar 7, 2017 at 9:07

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.