Does anyone know how to remove the renderings from a Sitecore item?
I want to remove all of the sublayouts so I can replace them with a new set. I have tried this
I think your exception is unrelated. To actually save your changes, you need to edit the item. Be sure you always access and update the value throgh LayoutField.Value
.
LayoutField layoutField = new LayoutField(item.Fields[Sitecore.FieldIDs.LayoutField]);
LayoutDefinition layout = LayoutDefinition.Parse(layoutField.Value);
//make your changes to the LayoutDefinition here
item.Editing.BeginEdit();
layoutField.Value = layout.ToXml();
item.Editing.EndEdit();