Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
    
Thanks, it works. I only get new errors when creating new folders, but I suppose it's a new issue :-) –  Marius Kay Jan 7 '13 at 12:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.