Im trying to do a seamingly simple task in SP 2013.

when the user either Creates a new doc (Ribbon>Files>New Document) or Uploads a File i want them renamed to for example [original_filename]_[datetime].[ext]

I have added a feature receiver (ItemAdded-synchronous) and the core of this is(from this QA) :

file.MoveTo(pathBeforeFileName + "/"+newFileName);

When I create new document it works as expected, but when I upload a doc, I get a file not found error right before the properties dialog pops up (or instead of it). The file is renamed correctly when I Close the error dialog.

Am I missing a ways to inform SP that I have renamed the file, its obviously looking for to old filename?

If this is impossible to do, is there any way to distinguish "New Doc" from "Upload Doc"?

More details: I have updated item2[SPBuiltInFieldId.FileLeafRef], but no difference. I have changed back to asynchronous event receiver then I will get past the first error message and get to the properties-dialog, but then I get Another error message at the bottom of that saying "The file [new filename] has been modified by [me] on [datetime]"

  • Did you ever find a solution to this problem? I have the same problem. – Mikkel Nielsen Apr 21 '15 at 12:18
  • Hi Mikkel. No we went for a different approach instead, so the users didnt upload documents, instead they were generated from forms (for other reasons, but we got rid of this problem as well) – Cowborg Apr 27 '15 at 13:56
  • Ok. crap... But thanks for your answer. For others: Think I have narrowed the problem down to this: File.moveto() is a async operation. And the list is reloaded before the file is moved and expexting the file to be in the new place. Or the opposite. – Mikkel Nielsen Apr 28 '15 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.