2015-09-02 97 views
0

我有分配給分類法的Ektron中存儲的內容項目。我試圖創建一個方法,這將允許我以編程方式更改分類法。到目前爲止,我通過ID找到內容項,並且能夠檢索其分類法,但我不知道如何更改它們。添加並從分類中刪除Ektron內容項目? (C#)

var ektronItem = contentManager.GetItem((long) item.tctmd_id); 
if (ektronItem != null) // item exists in Ektron 
{ 
    var newTaxonomies = item.taxonomy_ids; 

    var taxonomyAPI = new Taxonomy(); 
    var taxData = taxonomyAPI.ReadAllAssignedCategory(ektronItem.Id); 

    foreach (var tax in taxData) 
    { 
     taxonomyAPI.RemoveTaxonomyItem(???); 
     // here I'm trying to remove the content item from the taxonomy 
    } 
} 

taxonomyAPI.RemoveTaxonomyItem()需要一個Ektron.Cms.TaxonomyRequest對象,但我不知道如何創建此。我也不確定這是否是我應該使用的方法。

回答

0

如果任何人想知道如何做到這一點,這是我想出瞭解決方案:

var contentManager = new Ektron.Cms.Framework.Content.ContentManager(); 
var criteria = new Ektron.Cms.Content.ContentCriteria(ContentProperty.Id, EkEnumeration.OrderByDirection.Ascending); 
criteria.AddFilter(ContentProperty.FolderId, CriteriaFilterOperator.EqualTo, toUpdate.folder_id); 
criteria.OrderByDirection = Ektron.Cms.Common.EkEnumeration.OrderByDirection.Descending; 
criteria.OrderByField = Ektron.Cms.Common.ContentProperty.GoLiveDate; 
criteria.FolderRecursive = true; 
criteria.PagingInfo = new Ektron.Cms.PagingInfo(50, 1); 

var ektronItem = contentManager.GetItem((long) item.tctmd_id); 
if (ektronItem != null) // item exists in Ektron 
{ 
    // update taxonomy in Ektron 
    var taxIds = item.taxonomy_ids; 

    var taxonomyAPI = new Taxonomy(); 
    var taxData = taxonomyAPI.ReadAllAssignedCategory(ektronItem.Id); 

    var taxManager = new Ektron.Cms.Framework.Organization.TaxonomyItemManager(); 

    var taxCriteria = new TaxonomyItemCriteria(); 
    // create a taxonomy criteria of the item ID 
    taxCriteria.AddFilter(TaxonomyItemProperty.ItemId, CriteriaFilterOperator.EqualTo, item.tctmd_id); 
    // get all taxonomy items with item ID 
    var taxItems = taxManager.GetList(taxCriteria); 
    // determine taxonomyItemType 
    var type = taxItems.FirstOrDefault().ItemType; 

    foreach (var tax in taxData) 
    {      
     // delete from old taxonomies 
     taxManager.Delete(tax.Id, (long)item.tctmd_id, type); 
    } 

    foreach (var tax in taxIds) 
    { 
     // add to new taxonomies 
     var taxonomyItemData = new TaxonomyItemData() 
     { 
      TaxonomyId = tax, 
      ItemType = type, 
      ItemId = (long)item.tctmd_id 
     }; 
     try 
     { 
      taxManager.Add(taxonomyItemData); 
     } 
     catch (Exception ex) 
     { 

     } 
    } 
} 
+0

我創造在C#中的新內容。我如何檢查是否存在帶有「標題」的內容,因此我不會在標題末尾創建帶有下標的新內容? – Si8