Portal Engine
Version 3.x > Portal Engine > 2Qs: Adding new document (node) by code when Doc Name Source an existing field and InsertAsNewCultureVersion usage View modes: 
User avatar
Guest
dave.diehl-asg - 8/20/2008 12:20:37 PM
   
2Qs: Adding new document (node) by code when Doc Name Source an existing field and InsertAsNewCultureVersion usage
The subject pretty well describes what I'm looking for, but let me elaborate.

I want to add a new document from code, and have done so successfully, but I'm not confident that I'm doing it the preferred way.

If the document type of the document I'm trying to add is set to use the Document Name from an existing field and NOT an "extra field", what do you do with the NodeName property of the new node?

For example, the following code works, but I'm not sure it's right...
nodTemp = New CMS.TreeEngine.TreeNode("Foo.Bar")
nodTemp.NodeName = "Foobar1"
nodTemp.NodeAlias = "Foobar1"
nodTemp.DocumentCulture = "en-us"

Why wouldn't I assign the property instead of the NodeName? E.g. If "Foo.Bar" is defined so the Document name is set to the value of the field "SomeField", shouldn't this be sufficient?

nodTemp.SetValue("SomeField", "Foobar1")

Also...on the second question. I'm not totally sure how to use the InsertAsNewCultureVersion method. When creating nodes in code for documents that may already exist for another culture, is the following (in pseudocode) sufficient?

Do SelectSingleNode using preferred culture.
if nothing found
  Do SelectSingleNode using ALL_CULTURES
  if found
    set DocumentCulture of found node to preferred culture.
    Do InsertAsNewCultureVersion
  else
    Create new node
else
    node already exists.


User avatar
Kentico Consulting
Kentico Consulting
kentico_borisp - 8/21/2008 4:52:29 AM
   
RE:2Qs: Adding new document (node) by code when Doc Name Source an existing field and InsertAsNewCultureVersion usage
Hello Dave,

Could you please go through the chapter "Managing documents" (http://www.kentico.com/docs/devguide/content_management_internals.htm) and "Managing documents with workflow" (http://www.kentico.com/docs/devguide/versioning_internals.htm) in our developers guide?

I think this may help you.

Best Regards,
Boris Pocatko.