Update ReadOnly Property during EventsPublishedContent

Ayo
Ayo
Vote:
 

First, I want to add a readonly type property to my page type, is this possible? 
What I want is a string property that can be updated programicly, but not through the UI, and I would like the content editor to be able to see the value but not change it.

Assuming that is possible how do I update this property value during the Publish Event.

So how do I.... 

private void EventsPublishedContent(object sender, ContentEventArgs e)
{

     if (e.Content is MyPageType)
     {

         var myvalue = BussinessLogic.PerformAction(e.content)

          //Now I want to save myvalue on to a property in 
          //e.content.myProperty

      }
}
#190656
Edited, Apr 13, 2018 17:15
Vote:
 

How to make a readonly property http://www.jondjones.com/learn-episerver-cms/episerver-developers-guide/episerver-properties/how-to-hide-a-property-in-episerver-cms-and-how-to-make-a-property-readonly

To edit this property and change the data call .CreateWritableClone() on the type e.g. e.Content.CreateWritableClone() as content is readonly until you do this (You may need to cast e.Content in to the type first to be able to access .CreateWritableClone()).

You can then IContentRepository's (inject this in to your code) method Save() to save this data. If you want to directly update it I would suggest SaveAction.Patch when saving as this doesn't create a new version.

#190658
Edited, Apr 13, 2018 18:08
* 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.