문제

I have a document library. In ItemUpdated I move the file to a different location (based on date) and I want to add some metadata in ItemFileMoved to the file's new columns (which I added). The problem is I receive an error related to ItemFileMoved:

<nativehr>0x81020015</nativehr><nativestack></nativestack>The file file/path has been modified by Domain/User on 04 Jan 2013 10:36:02 +0100.

This is my code in ItemFileMoved:

base.ItemFileMoved(properties);
SPListItem movedFile = properties.ListItem;
// some changes to my columns
movedFile.Update();

I'm not sure what I am doing wrong. My questions are: 1) Is the problem in the way I get the item? How can I get an SPListItem for a file if not using properties.ListItem? 2) Is it better to modify files metadata in ItemUpdated before I use file.MoveTo?

Thank you in advance for any help.

도움이 되었습니까?

해결책

I have not personally run into this issue but it sounds a lot like an unsafe update error. Assuming properties.ListItem is a reference to the newly moved file and not null or somehow have a reference to the old file location, you can try something like this:

movedFile.Web.AllowUnsafeUpdates = true;
movedFile.Update();
movedFile.Web.AllowUnsafeUpdates = false;

Another theory you can play with - I've also seen some interesting behavior with events that depends on base.Event(properties) and where it is in the code. This was a long time ago so I don't remember specifics on what worked for me or what issue I was having, but you could try moving it to the end instead of the beginning of your method call, or removing it altogether and see what happens.

Hopefully something here can help you out.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top