Using methods from IContentLoader or IContentRepository to get existing data, it will be returned as read-only version. If you try to update and save it, you will get a ReadOnly exception, although the model has the public set available
Since the API assume that most of the time are read operations, than it shares the instance object on multiple threads. This reduces the amount of short-lived objects and reduce the memory need for the website.
If you want to change programmatic the property, you need to access to a writable clone of the current instance object. Then you can change it and request to save it. The property IsReadOnly gives information about if is a read-only or cloned instance.
The following code, update a property named “MyProperty” with a new text and publish the page with the new content.
var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
var contentReference = new ContentReference(23123);
var readOnlyPage = contentRepository.Get<ContentPage>(contentReference);
var clonedPageInstance = readOnlyPage.CreateWritableClone<ContentPage>();
clonedPageInstance.MyProperty = "The new value";
contentRepository.Save(clonedPageInstance, SaveAction.Publish, AccessLevel.NoAccess);
The SaveAction is an enum type of save to perform on the page data object
Member name | Member summary |
---|---|
None | Do not save data. |
Save | Save a page, leaving it in a checked out state. |
CheckIn | Save and check in page, creating a new version only if necessary. |
Publish | Publish page, creating a new version only if necessary. |
Reject | Reject a checked-in page. |
ForceNewVersion | Flag that is used to force the creation of a new version. |
ForceCurrentVersion | Save and check in page, always updating the current version |
SkipValidation | Does not validate the data against IValidationService |
DelayedPublish | Save and check in page, creating a new version only if necessary and sets the content as delayed publish. |
ActionMask | Mask to clear Force… settings from SaveAction |
GetOriginalType | Gets the Type of the current object, ensuring that the eventual type that could be generated by a proxy interceptor is ignored. |
The AccessLevel determine the minimum access level that the current user must have to save the content.
Member name | Member summary |
---|---|
NoAccess | No access to an item |
Read | Read access to an item |
Create | Create access for an item, i e create new items below this item |
Edit | Change / create new versions of this item |
Delete | Delete this item |
Publish | Publish/unpublish items and versions of an item |
Administer | Set access rights for an item |
FullAccess | Full access for an item |
Undefined | Access level not defined. |
GetOriginalType | Gets the Type of the current object, ensuring that the eventual type that could be generated by a proxy interceptor is ignored. |