In this article I would like to share the code to get the Image from an APP host web picture library in a SharePoint hosted APP.
Use the following code to get an image from a library using the JavaScript object model:
- getLibraryfromHostweb: This method is used to get all the libraries from the app host web.
- IsListExist: On the success method of getLibraryfromHostweb, it will check whether the library (var libraryName = "NewsPictureLibrary";) is already available or not.
- getListItemCollection: If the list is available it will call the getListItemCollection method, it will get the item collection from the current library with Query.
- OnGetListItemSuccess: Then finally get the image name from the current library in this success event.
Variables declaration:
In the AppManifest.xml file give read permission to the Site Collection.
Summary
In this article we explored how to get an image from a SharePoint app host web picture library using the JavaScript object model in a SharePoint Hosted App.