0

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

0

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');           
    context.executeQueryAsync(
        Function.createDelegate(this, function () { retrieveListItemFromUrlResult(f); }),
        Function.createDelegate(this, this.onErrorHandler)
    );
}

function retrieveListItemFromUrlResult(f) {     
    var item = f.get_listItemAllFields();   
    console.log(item.get_fieldValues().ColumnName);
}

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.

0

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
context.load(file,'ListItemAllFields'); 

context.executeQueryAsync(function(){
    var listItem = file.get_listItemAllFields();
    var customColumn = listItem.get_fieldValues().customColumn;  //use internal name of column
    console.log(customColumn);
},function(sender,args){
    console.log("something went wrong " + args.get_message());
});

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.