Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 25064

Rename document in ItemAdded Event error.

$
0
0

Hello,

I am renaming a document in a document library in an ItemAdded Event Handler.  I have set the event handler to runsynchronously.

My problem is that after the handler runs (I rename the file and update it), the automatic redirect from the Upload.aspx page to the EditForm.aspx breaks with this error:

[FileNotFoundException: <nativehr>0x80070002</nativehr><nativestack></nativestack>]
   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) +42726969
   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
   Microsoft.Office.RecordsManagement.PolicyFeatures.ApplicationPages.UploadPage.OnSubmit(Object o, EventArgs e) +2481
   Microsoft.Office.RecordsManagement.PolicyFeatures.ApplicationPages.UploadExPage.OnSubmit(Object o, EventArgs e) +281
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint

Here is my code:

            SPFile file = _currentItem.File;
            string oldFileUrl = file.Url;
            string oldFileName = file.Name;
            string docFileExtension = Path.GetExtension(oldFileName);

            string newFileName = guid.ToString() + docFileExtension;
            string newFileUrl = oldFileUrl.Replace(oldFileName, newFileName);
            base.EventFiringEnabled = false;
            file.MoveTo(newFileUrl, true);
            file.Update();                   
            base.EventFiringEnabled = true;

Any ideas what I am missing?

B. regards.


Viewing all articles
Browse latest Browse all 25064

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>