1

im trying to rename a document in the ItemAdded event receiver with the following code:

 public override void ItemAdded(SPItemEventProperties properties)
 {
        properties.ListItem[SPBuiltInFieldId.FileLeafRef] = properties.ListItem.ID + " " + properties.ListItem.Name;
        properties.ListItem.SystemUpdate();

        base.ItemAdded(properties);
 }

The code works fine when i upload a file via drag and drop but when i use the upload file dialog, Sharepoint displays the following error after clicking on OK in the dialog:

 [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) +2415
   Microsoft.SharePoint.SPWeb.GetFileOrFolderProperties(String strUrl, ListDocsFlags listDocsFlags, Boolean throwException, SPBasePermissions& permMask) +165
   Microsoft.SharePoint.SPFile.PropertiesCore(Boolean throwException) +95
   Microsoft.SharePoint.SPFile.get_Length() +14
   Microsoft.Office.RecordsManagement.PolicyFeatures.ApplicationPages.UploadPage.OnSubmit(Object o, EventArgs e) +7611
   Microsoft.Office.RecordsManagement.PolicyFeatures.ApplicationPages.UploadExPage.OnSubmit(Object o, EventArgs e) +212
   System.Web.UI.HtmlControls.HtmlInputButton.OnServerClick(EventArgs e) +134
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5062

Can anyone help me with this issue?

Thanks in advance

  • Add full code..? – user37251 Sep 12 '17 at 8:12
  • this is the full code (only without the method name): public override void ItemAdded(SPItemEventProperties properties) { properties.ListItem[SPBuiltInFieldId.FileLeafRef] = properties.ListItem.ID + " " + properties.ListItem.Name; properties.ListItem.SystemUpdate(); base.ItemAdded(properties); } – Bernhard Sep 12 '17 at 8:21

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.