这是我尝试的代码,相同的代码在项目保存事件上为我工作。
public void OnPublishEnd(object sender, EventArgs args)
{
SitecoreEventArgs eventArgs = args as SitecoreEventArgs;
Item item = eventArgs.Parameters[0] as Item;
}
“item”返回null。我应该在这里使用什么来从eventargs获取项目?
答案 0 :(得分:3)
想出来,
SitecoreEventArgs eventArgs = args as SitecoreEventArgs;
Item item = ((Sitecore.Publishing.Publisher)(eventArgs.Parameters[0])).Options.RootItem as Item;//eventArgs.Parameters[0] as Item;
Item existingItem = item.Database.GetItem(item.ID, item.Language, item.Version);
这很有用!