我有一段代码,我试图在编辑文件时禁用事件触发,一旦调试器点击 item.SystemUpdate(false) 行,它就会抛出一个异常,指出“文件 xxxx 已被 xxxxx 修改”
HandleEventsFiring handle = new HandleEventsFiring();
handle.DisableHandleEventFiring();
try
{
web.AllowUnsafeUpdates = true;
SPFile rptFile = web.GetFile(item.Url); //item is an SPListItem
if (rptFile.Exists)
{
WordDocUtility word = new WordDocUtility();
using (System.IO.Stream stream = rptFile.OpenBinaryStream())
{
word.ReplaceKeys(stream, keys);
rptFile.SaveBinary(stream);
}
}
item.SystemUpdate(false); // the line throwing the exception
}
finally
{
handle.EnableHandleEventFiring();
web.AllowUnsafeUpdates = allowUnsafeUpdates;
}
public class HandleEventsFiring: SPItemEventReceiver
{
public void DisableHandleEventFiring()
{
this.EventFiringEnabled = false;
}
public void EnableHandleEventFiring()
{
this.EventFiringEnabled = true;
}
}
有谁知道解决这个问题的方法还是我做错了什么?
任何帮助将不胜感激。