1

How to retrieve document or Video file extension from SharePoint library using COM JavaScript

but i Tried this code but Error will be like this:

$(document).ready(function() 
        {
             LoadZipCodes();
             alert("Ftc");
        });

function LoadZipCodes()
    {
        $.ajax({ ///MyLearning/My%20Learning%20Videos/HaysLMS?Web=1
                url:"http://vm-srv-hays:2015/_api/web/GetFolderByServerRelativeUrl(\'/My Learning Videos/Hays-SP2013/')/files",
                method: "GET",
                headers: { "Accept": "application/json; odata=verbose" },
                success : function(data){ //data will have the video object
                //var name = data.d.results[0].Name;
                //console.log(title); 
                alert(JSON.stringify(data));
                },
                error : function(args) {
                console.log(args);
                }});

}

enter image description here

  • You are retrieving this from an asset library or a document library? And please elaborate your question more. Details on what you have done, where you are retrieving from will be helpful. – Akhoy Aug 25 '15 at 9:57
  • I want to retrieving from asset library. – SNGOKUL Aug 25 '15 at 9:58
  • i retried file name but , I need file name with their Extension, Example Video.mp4, – SNGOKUL Aug 25 '15 at 10:03
  • 1
    This is not an error. It's the JSON string that you're alerting. Looking at that, no data is being returned. Make sure your server relative url is correct. – Akhoy Aug 25 '15 at 14:37
1

When a video (Content type: Video) is stored in the asset library, they are stored as folders with folder name being the video name. What you are getting is only the name of the folder. The properties (URL, full name) and the video itself are stored within the folder as another content type known as Video Rendition. Getting the actual video can be done using REST api with the following url:

http://siteurl/_api/web/GetFolderByServerRelativeUrl('/Video Name')/Files.

Update:

$.ajax({
url: 'https://siteUrl/_api/web/GetFolderByServerRelativeUrl(\'/AssetLibName/VideoName\')/files',
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success : function(data){ //data will have the video object
var name = data.d.results[0].Name;
console.log(title); 
},
error : function(args) {
console.log(args);
}});

Note: Server Relative URL will change based on where the video is stored i.e. location of site collection / subsite.

  • Thank you ! can you show me the full code ? its will be helpful for me – SNGOKUL Aug 25 '15 at 10:11
  • I try this code 'url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/GetFolderByServerRelativeUrl('Hays-SP2013')/Files.' Error:Uncaught SyntaxError: Unexpected token ILLEGAL – SNGOKUL Aug 25 '15 at 10:58
  • @SNGOKUL check updated answer. – Akhoy Aug 25 '15 at 11:04
  • @SNGOKUL I noticed you unmarked it as answer. Let me know what is not working in this so I can help you. – Akhoy Aug 25 '15 at 12:15
  • I tried this code – SNGOKUL Aug 25 '15 at 13:27

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.