Override readonly property and save new value

Vote:
 

Ì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.

#80942
Feb 05, 2014 14:33
Vote:
 

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."

#80943
Feb 05, 2014 14:36
Vote:
 

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

var writablePage = data.CreateWritableClone();

    

 

#80949
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.