I am trying to change a field value dynamically from back-end, but looks like the changes are not being saved.
Code
item
is fetched from the master database.
using (new EditContext(item))
{
item.Editing.BeginEdit();
try
{
//Value is updated here from "" to Test
item.Fields["Content"].Value = "Test";
}
finally
{
//item.Fields["Content"].Value is "" again.
item.Editing.AcceptChanges();
item.Editing.EndEdit();
}
}
UPDATE
As @sitecore climber said, I did change my code back to use -
new Sitecore.SecurityModel.SecurityDisabler()
However, the issue was caching. The updated value was displayed in the content editor, only after I had cleared the cache and restarted the browser.
To get around that, I disabled caching before making the edit and turned it back on once the editing was done.
CacheManager.Enabled = false;
using (new Sitecore.SecurityModel.SecurityDisabler())
{
item.Editing.BeginEdit();
try
{
item.Fields["Content"].Value = "Test";
}
finally
{
item.Editing.EndEdit();
}
}
CacheManager.Enabled = true;