AnsweredAssumed Answered

Trouble in Updating an item's references

Question asked by ben deng on Nov 5, 2010
Latest reply on Nov 13, 2010 by ben deng

Hi,All

     Pls see the flowing code, it can only update parent Item references with the same folder child items,or else nothing change at the end.

 

     If delete "fileItem.UnlockFile(0, "API AddChildItems", (int)EdmUnlockFlag.EdmUnlock_Simple, null);" then run, may see the references in the items explorer,but can not see check in dialog, that is the problem.

 

     could somebody help me  solve this problem?

        public static bool AddChilds(int parentItemId, List<IEdmItem> childItems, IEdmVault11 vault)
        {
            bool flag = true;
            if (null == MyEdmItem.GetItemById(parentItemId, vault) || childItems.Count <= 0)
            {
                return false;
            }
            foreach (IEdmItem it in childItems)
            {
                if (null == it)
                {
                    flag = false;
                    return false;
                }
            }

            int num = childItems.Count;
            Array addRefs = Array.CreateInstance(typeof(EdmItemRef), num);
            EdmItemRef[] tmpAddRefs = new EdmItemRef[num];
            IEdmItem parentItem = MyEdmItem.GetItemById(parentItemId, vault);
            for (int i = 0; i < num; i++)
            {
                EdmItemRef iref = new EdmItemRef();
                iref.moParentNamePathOrItemID = parentItemId;
                iref.moNamePathOrID = childItems[i].ID;
                iref.mlEdmRefFlags = (int)EdmRefFlags.EdmRef_Item+(int)EdmRefFlags.EdmRef_Static;
                tmpAddRefs[i] = iref;
            }
            addRefs = tmpAddRefs;
            
            Array removeRefs = null;
            
            
            IEdmFile8 fileItem = (IEdmFile8)parentItem;
            if (!fileItem.IsLocked)
            {
                try
                {
                    fileItem.LockFile(vault.RootFolderID, 0, (int)EdmLockFlag.EdmLock_Simple);
                }
                catch (System.Exception e)
                {
                    vault.MsgBox(0, e.Message, EdmMBoxType.EdmMbt_OKOnly, "");
                    return false;
                }
            }

            parentItem.UpdateReferences(ref addRefs, ref removeRefs);
            
            fileItem = (IEdmFile8)parentItem;
            fileItem.Refresh();
            try
            {
                 fileItem.UnlockFile(0, "API AddChildItems", (int)EdmUnlockFlag.EdmUnlock_Simple, null);
            }
            catch (System.Exception e)
            {
                vault.MsgBox(0, e.Message, EdmMBoxType.EdmMbt_OKOnly, "");
                return false;
            }
           return flag;
        }

Outcomes