Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have slightly adjusted your code and now it's working:</p> <pre><code> private string CreateNewItemCopy(string title, RepositoryLocalObjectData source, string filename) { string newItemUri = ""; try { ItemType tridionItemType = GetTridionItemType(source); string orgItemUri = source.LocationInfo.OrganizationalItem.IdRef; if (tridionItemType == ItemType.Component) { ComponentData sourceComp = source as ComponentData; ComponentData newComponent = client.GetDefaultData(tridionItemType, orgItemUri) as ComponentData; newComponent.Title = title; newComponent.Metadata = source.Metadata; // ** Only Component has .Content and SchemaRef newComponent.Content = sourceComp.Content; newComponent.Schema.IdRef = sourceComp.Schema.IdRef; newItemUri = client.Create(newComponent, new ReadOptions()).Id; } else if (tridionItemType == ItemType.Page) { PageData sourcePage = source as PageData; PageData newPage = client.GetDefaultData(tridionItemType, orgItemUri) as PageData; newPage.Title = title; newPage.Metadata = source.Metadata; // ** Only Page has .Filename newPage.FileName = filename; newItemUri = client.Create(newPage, new ReadOptions()).Id; } else //I would really like to handle all things here - but have problems with item-specific mandatory properties, such as Schema, Filename, and Dir { var newGenericTridionItem = client.GetDefaultData(tridionItemType, orgItemUri) as RepositoryLocalObjectData; newGenericTridionItem.Title = title; newGenericTridionItem.Metadata = source.Metadata; //if(GetTridionItemType(newGenericTridionItem.Id) == ItemType.Page) // newGenericTridionItem.filename; newItemUri = client.Create(newGenericTridionItem, new ReadOptions()).Id; } } catch (Exception ex) { throw; } return newItemUri; } private ItemType GetTridionItemType(RepositoryLocalObjectData source) { string itemType = source.GetType().Name; switch (itemType) { case "ComponentData": return ItemType.Component; case "PageData": return ItemType.Page; } return ItemType.UnknownByClient; } </code></pre> <p>But I still don't understand why do you want to do it this way and not use simple Copy method?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload