I have url like "http://test/site/subsite/docslibrary/filename.doc" I need to get one of custom columns of file in future, so need access this file in sharepoint.

Thank you

2 Answers 2


Try something like this:

function retrieveListItemFromUrl() {        
    var context = new SP.ClientContext.get_current();
    var web = context.get_web();
    var url = "http://test/site/subsite/docslibrary/filename.doc";
    var f = web.getFileByUrl(url);          
    context.load(f, 'ListItemAllFields');           
        Function.createDelegate(this, function () { retrieveListItemFromUrlResult(f); }),
        Function.createDelegate(this, this.onErrorHandler)

function retrieveListItemFromUrlResult(f) {     
    var item = f.get_listItemAllFields();   

function onErrorHandler(sender,args)
    console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

You should replace the value of url variable and the ColumnName in retrieveListItemFromUrlResult function to match your data.
Also, the code should run in context of the web that contains the document library. If that is not the case, you should create the context object providing the url of the web that contains the document library.


You need to use the getFileByServerRelativeUrl method to get the file and then load the list item to get all properties as below;

var context = SP.ClientContext.get_current(); 
var file = context.get_web().getFileByServerRelativeUrl("http://test/site/subsite/docslibrary/filename.doc");   //get file

    var listItem = file.get_listItemAllFields();
    var customColumn = listItem.get_fieldValues().customColumn;  //use internal name of column
    console.log("something went wrong " + args.get_message());

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.