API
Version 7.x > API > API manipulation of ediatble text field works only in preview mode View modes: 
User avatar
Certified Developer 8
Certified Developer 8
nrinat-ecentricarts - 8/22/2013 2:37:27 PM
   
API manipulation of ediatble text field works only in preview mode
Hello

I have an editable text field that I manipulate with API at a web part page load event:
PageInfo pi = PageInfoProvider.GetPageInfo(CMSContext.CurrentDocument.DocumentGUID);
string TheContent = pi.EditableWebParts["editabletext"];

// Manipulate content here

pi.EditableWebParts["editabletext"] = TheContent;

TreeProvider tr = new TreeProvider();
TreeNode tn = tr.SelectSingleNode(CMSContext.CurrentDocument.DocumentID);

// Update the content XML
tn.SetValue("DocumentContent", pi.DocumentContent);

// Update the document
DocumentHelper.UpdateDocument(tn, tr);

I can see the manipulated text in preview mode only. I assumed I had a caching problem. So after saving the document I tried all cachine clearing methods I could find:
CMS.GlobalHelper.CacheHelper.ClearOutputCache(CMSContext.CurrentSiteID, CMSContext.CurrentPageInfo.NodeAliasPath, CMSContext.CurrentDocument.DocumentCulture, true, true);
CMS.GlobalHelper.CacheHelper.ClearFullPageCache();
CMS.GlobalHelper.CacheHelper.ClearPartialCache();

Clearing the cache did not help.

Any ideas?

Thank you!

Norm

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 8/23/2013 5:31:41 AM
   
RE:API manipulation of ediatble text field works only in preview mode
Hi,

Are you using workflows or versioning? Do you see the correct content in DocumentContent column in CMS_Document table?

Have you tried using the LoadContent/SaveContent methods from CMSAbstractEditableWebPart class?

Best regards,
Juraj Ondrus

User avatar
Certified Developer 8
Certified Developer 8
nrinat-ecentricarts - 8/23/2013 1:34:58 PM
   
RE:API manipulation of ediatble text field works only in preview mode
Thank you Juraj! I followed your lead and it worked.

The user control now inherits from CMSAbstractEditableWebPart and overrides the Save method:
public override void SaveContent(CMS.DocumentEngine.PageInfo pageInfo)
{
string TheContent;
if (_TOC.CreateTOC(pageInfo, out TheContent))
pageInfo.EditableWebParts["editabletext"] = TheContent;
}

However I am not sure why it was needed. Would you mind explaining the issue so that I will share the knowledge with my team mates?

Thanks again,
Norm

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 8/26/2013 2:07:50 AM
   
RE:API manipulation of ediatble text field works only in preview mode
Hi,

The content of editable region is stored in CMS_Document table in DocumentContent column. However, this is for published documents. If you are using workflows, the unpublished data are saved to the version history tables (DB tables sctructure).


Best regards,
Juraj Ondrus