Get the Personalized Datasource of a Sitecore Item
I recently came across a problem where i had to programmatically get the datasource of a View Rendering of a Sitecore item. This is a datasource that may potentially be personalised.
The method i put together requires the Item, the Placeholder name, and the Id of the View Rendering in this placeholder.
e.g. if I have a “Landing Page” item on my website, which has a “bottomPane” placeholder. This placeholder has a “Call To Action” View Rendering in it. The datasource for this View Rendering is personalised. Using this function i can get the datasource from this instance of the “Call to Action” widget for use elsewhere (in my case it was a navigation menu).
Example Usage:
Here is the Class: