Override readonly property and save new value


Ìs it possible to override a readonly property and save it's new value using c# code?

I have an old custom property on my page that I need to be able to override and save new values to since the old code dosen't seem to work longer and save to.

Feb 05, 2014 14:33

This is my code that I am using:

var fileList = this.SliderPages;
                string serializedString = string.Empty;

                if (fileList.Count > 0)
                    using (MemoryStream tempMemory = new MemoryStream())
                        BinaryFormatter binaryFormatter = new BinaryFormatter();
                        binaryFormatter.Serialize(tempMemory, fileList);
                        serializedString = System.Convert.ToBase64String(tempMemory.ToArray());

                DataFactory factory = EPiServer.DataFactory.Instance;
                var data = factory.GetPage(this.CurrentPage.PageLink);

                data.SetValue(this.PropertyName, serializedString);

                factory.Save(data, EPiServer.DataAccess.SaveAction.Save);


This is the error I get:

Message = "The property SliderBox is read-only."

Feb 05, 2014 14:36

Before you can set new value. you need a writeable clone of the page data object:

var writablePage = data.CreateWritableClone();



Feb 05, 2014 15:23
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.