1

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());
  });
  • I am getting error Value does not fall within the expected range – sachin Mar 7 '17 at 8:40
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());
  });
  • Update code It works for me – sachin Mar 7 '17 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.

  • It is giving error ListItemAllFields not defined – sachin Mar 7 '17 at 9:07

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.