Sunday, 1 February 2015

SharePoint 2013: Image Rendition location & automation

In this post I wont just list how and where Image rendition stored in SharePoint 2013 , I will provide a walk-through on how you can discover this on your own without relaying on Google Search or any other blog posts.

If you are not familiar with the "Image Rendition Feature" which is newly introduced in SharePoint 2013  please refer to Waldek's  excellent blog post here.

If you used image rendition before you will notice that the ID is not easily maintainable as It's a counter once you add a new item the ID is automatically given as the previous value+1.

another important thing to share that in SharePoint 2013 there are 2 different kinds of Image rendition , the predefined ones which you define by navigating to site settings ->Image rendition. The other kind is what I call "on the fly" which you refer to an image by width and height. {ImageUrl}?width=300&height=150

For the second type you can't update a specific picture's image rendition unless you already have a rendition predefined with the same dimensions.

To elaborate more in the below screenshot you can see an image rendered with width=300 and height =150  which is generated without predefined rendition.


Let's go back to the main point of the post which is how the image rendition is stored in the SP site collection.

If you have any  decompiler like ILSPY just copy the ISAPI folder from your Hive 15 folder to ILSPY folder ,load SharePoint assemblies in particular Microsoft.SharePoint.Publishing.dll , then in the search bar type rendition and wait for the results as shown below:


Select the ImageRenditionCollection and choose   SetRenditions Method


In this method you will find that the file been loaded and edited is located at the below path



from the above you can tell that the Rendition are stored in a single XML file under the masterpage folder.

As a conclusion to automate the creation of your predefined Image renditions you can add an xml file to a Module element and deploy the publishedImageRendition file to automate the creation of the image rendition instead of using the ImageRenditionCollection.Add Method in a feature activation code.
If you are using Office 365 you can either build a sandbox solution or refer to my previous post to use your App as module element to upload files to SharePoint using Remote event receiver.



Related Articles

0 comments:

Post a Comment