1

IN my event receiver, on Item Added event I have placed my custom method to move document based on a rule. The issue is when a document is uploaded in the Upload dialog I get an error saying item not available.

System.IO.FileNotFoundException [FileNotFoundException: 0x80070002]
Microsoft.SharePoint.Library.SPRequestInternalClass.GetFileAndFolderProperties(String bstrUrl, String bstrStartUrl, ListDocsFlags ListDocsFlags, Boolean bThrowException, Int32& phrStatus, Object& pvarFiles, Object& pvarDirs, UInt32& pdwNumberOfFiles, UInt32& pdwNumberOfDirs) +0
Microsoft.SharePoint.Library.SPRequest.GetFileAndFolderProperties(String bstrUrl, String bstrStartUrl, ListDocsFlags ListDocsFlags, Boolean bThrowException, Int32& phrStatus, Object& pvarFiles, Object& pvarDirs, UInt32& pdwNumberOfFiles, UInt32& pdwNumberOfDirs) +40768117 Microsoft.SharePoint.SPWeb.GetFileOrFolderProperties(String strUrl, ListDocsFlags listDocsFlags, Boolean throwException, SPBasePermissions& permMask) +173
Microsoft.SharePoint.SPFile.PropertiesCore(Boolean throwException) +101 Microsoft.SharePoint.SPFile.get_Length() +11 Mirosoft.SharePoint.ApplicationPages.UploadPage.OnSubmit(Object o, EventArgs e) +2506 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3804

Tried the below code in the ItemAdded method after executin my custom method

properties.ErrorMessage = "Item moved to the target library";
properties.Status = SPEventReceiverStatus.CancelNoError;

But still I get the error even though the file is successfully moved to the destination library as I needed. How can I prevent this error ?

  • The error is being thrown from upload page. I think its better to do this via a Workflow rather even reciever. – Amal Hashim Apr 15 '15 at 12:05
  • 1
    I've already seen this behavior, and if I remember correctly it happens in SP2013 and not in SP2010... The point is that the code of the Upload page deals with the SPFile after ItemAdded has run (witch is in my opinion a design error from MS). Trying with an async ItemAdded may only give you the same error on a random basis... Maybe a job, or an ER on check-in? – Evariste Apr 15 '15 at 12:11
  • Can you post you event receiver code? I have a hunch that disabling event firing in your code before you perform this operation might help? – Arsalan Shahid Apr 15 '15 at 16:11
  • Thanks all for the replies @Evariste it happens in ItemUpdated as well since I delete the file. The thing is i dynamically bind event receivers to document libraries. What's an ER ? Can a workflow be binded to library dynamically so that it will move the file. I need to move the file immediately when uploaded. I'm trying to create the DropOff library functionality in SharePoint Foundation. I don't think customizing the edit form will b a good idea. What do you think ? – Shaamil Apr 17 '15 at 5:57
  • ER = event receiver. Yes, a workflow can be trigerred when a file is added to the library. But Im not keen of WF in such scenarios: they're slow, buggy, and they're visible in the UI. However, I don't have a better ready-to-go solution for you at the moment. – Evariste Apr 17 '15 at 6:04
0

Have you considered using the Content Organizer feature to route documents to the appropriate location instead of using custom code?

  • I'm using SharePoint 2013 Foundation. Unfortunately the feature is not there – Shaamil Apr 16 '15 at 5:08

Your Answer

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

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