Sharepoint 2013-使用itemupdating或itemupdated事件更新文档元数据不起作用

时间:2013-12-16 23:03:23

标签: sharepoint eventreceiver

我正在尝试使用项目更新事件将文档添加到库时更新文档的自定义元数据,但它无法正常工作。自定义aspx应用程序使用href元素指向文档的URL。单击它打开Windows资源管理器视图类似于OOB sharepoint 2013资源管理器视图。现在,当用户通过复制粘贴选项将文档从library1(在sitecollection1中的site1中生活)复制到library2(位于sitecollection2中的site2中)时,我需要清除文档的一些元数据。我正在尝试Lukasz的建议,但元数据并未清除。在调试模式下,即使在更新之前禁用事件触发,我也会再次调用更新的事件,这很奇怪。最后,我的元数据未被清除。我尝试了更新和更新事件。任何的想法?这是我的更新代码:

public override void ItemUpdated(SPItemEventProperties properties)
        {
            base.ItemUpdated(properties);
            ClearNotes(properties);
        }

 private void ClearNotes(SPItemEventProperties properties)
        {
            try
            {
                SPListItem listItem = properties.ListItem;


                listItem["Notes1"] = string.Empty;
                listItem["ReviewNote"] = null;


                base.EventFiringEnabled = false;
                listItem.Update(); 
            }
            catch (Exception ex)
            {
               //logging error to db
            }
            finally
            {
                base.EventFiringEnabled = true;
            }
        }

1 个答案:

答案 0 :(得分:0)

我认为一定是这个.EventFiringEnable = false; 不是基础。 ...

你也可以使用itemupdating和Afterproperties来实现,然后你不需要禁用EventFiring而不需要更新:

public override void ItemUpdating(SPItemEventProperties properties)
        {
            base.ItemUpdating(properties);

            ///...
            properties.AfterProperties["Notes1"] = string.Empty;            
        }