API Questions on Kentico API.
Version 6.x > API > Updating EditableWebParts content via API View modes: 
User avatar
Member
Member
scott_hancock-urmc.rochester - 8/2/2012 2:49:12 PM
   
Updating EditableWebParts content via API
Hi,

I'm adding new pages and inserting text into the editable web part through the API. I'm seeing something in the database that concerns me. When I create a new page and insert some text the DocumentContent field in the CMS_Document table looks like this:

<content><webpart id="maincontent"><![CDATA[This is some more text]]></webpart></content>


However, I noticed that the content on other pages like this one looked like this:

<content><webpart id="maincontent;82037d0f-044c-4477-90da-2c3bed5738b1"><![CDATA[<p>
This is some more text</p>
]]></webpart></content>


The difference is the addition of the GUID after the webpart id. If I edit my page and save it, the GUID then appears like the others.

What's going on here?

Here is my code:


UserInfo user = UserInfoProvider.GetFullUserInfo("administrator");

TreeProvider tree = new TreeProvider(user);
TreeNode parentNode = tree.SelectSingleNode(CMSContext.CurrentSiteName, "/", "en-us");

System.Guid g = new Guid();
int nodeID = -1;

if (parentNode != null)
{
TreeNode newNode = TreeNode.New("CMS.MenuItem", tree);
newNode.DocumentName = "My New Document";
newNode.DocumentCulture = "en-us";
newNode.DocumentPageTemplateID = 77;
newNode.Insert(parentNode);
g = newNode.DocumentGUID;
nodeID = newNode.NodeID;
}

PageInfo pi = PageInfoProvider.GetPageInfo(g);
pi.EditableWebParts["mainContent"] = "This is some even more text";

TreeNode tn = tree.SelectSingleNode(nodeID);
tn.SetValue("DocumentContent", pi.DocumentContent);
tn.Update();


Also, what is the difference between using TreeNode.Update and DocumentHelper.UpdateDocument? I've seen both in your examples.

Thanks,
Scott

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 8/3/2012 2:38:11 AM
   
RE:Updating EditableWebParts content via API
Hi,

The GUID - this has no effect on the functionality and you should not concern about it. The GUID is added to ensure some backwards compatibility but it fact, it has no influence on this functionality.

The difference between TreeNode and DocumentHelper is that the second one is used for documents with workflow and it is also recommended to use it all the time - even if you are not using workflow. If you are not using workflow and you are using TreeNode class and in the future you will use the workflow - you will have to also rewrite your code to use DocumentHelper. When using the DocumentHelper from the begining, you won't need to change the code.

Best regards,
Juraj Ondrus