On a Sitecore 8.0 project I'm currently trying to programmatically update the datasource of a RenderingReference. Due to earlier decisions the datasource of renderings are not based in Id but on path.
With the following code im getting the rendering references, and updating the Datasources correctly within the method. But the changes are never saved to the database.
Is there something I'm doing wrong? Or am i trying to do something which is not possible?
page.Editing.BeginEdit();
var renderings = page.Visualization.GetRenderings(Sitecore.Context.Device, true);
foreach (var rendering in renderings)
{
rendering.Settings.DataSource = "A New DataSource";
}
page.Editing.EndEdit();