1

I coded an event receiver that renames for example a .txt file to a .text file (it does not matter the extensions, it is just an example). In my code what I do is to an SPFile.MoveTo operation. It works fine in SP2010 but when I execute the same code in SP 2013, when the operation is done using IE I get the text "Sorry, something went wrong" and then "File Not Found".

It's clear that the Sharepoint upload code tries to do things with the original name and it does not realize that it was renamed.

Can I do something from my event receiver code like using the AfterProperties to bypass this error?

Thanks

1
  • Have you used SPFile.MoveTo method (String, SPMoveOperations, Boolean) function ? Commented Nov 22, 2016 at 11:38

3 Answers 3

0

1st thing, if you share the code here then it will be great help to understand it. What you are trying to acheve, move the files to new location and then rename it?You can use copyto operation..

You can use After Properties to fix it,Check this post discuss the issue in details: Change name in ItemAdding event receiver or create a new Item

1
  • Thanks but the code is huge. I basically have an event receiver for ItemAdding or ItemUpdating and I work for SPFiles (that is, a typical Document Library) and it's just a matter of renaming the file name, not the path (so they remain in the same library). In SP2013 after you add a document if that document is for example a txt or a bmp then you can edit the properties and when editing the properties Sharepoint fails since it tries to use the old file name.
    – Paul
    Commented Dec 24, 2013 at 11:39
0

As you do a SPFile.MoveTo the file (altough it retains in the same docbib) is essentially moved to the new path. So therefore the old item does not exist anymore and a new one is created (of course together with triggering the Events ItemAdded by itself).

So after you called the MoveTo, all the following Eventreceivers which are called on the item will fail, because it simply does not exist anymore.

So you will have to cancel the further execution of event-Receiver-stack (but only for this Item!!!) as well as redirecting the user to the Editform, displaying the new Item (because the form is called with the id of list and item it should Display, which won´t work for the "1st"-Item anymore).

Simply changing anything in the after-properties won´t work, because following eventreceivers and forms still will use the SPContext.CurrentItem or properties.ListItem or properties.ListItemID, ... which won´t Change when editing the after-properties Array and simply Point to a listitem wich doesn´t exist anymore --> has to cause error

0

Not much information indeed. You could just change properties.ListItem["FileLeafRef"] property in ItemAdded Event in some cases. If all you need is just renaming.

2
  • Would you please elaborate your answer, on how not much information is available. And what could be the work around
    – Asad Refai
    Commented Jul 31, 2015 at 6:26
  • The main idea is: if renaming is the only need, why not use ItemAdded Event. But perhapse I don't know some aspects.
    – ilius33
    Commented Jul 31, 2015 at 7:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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