У меня есть существующий документ в библиотеке документов, и я пытаюсь перезаписать этот файл в коде, используя следующий код:
byte[] data = ...
SPListItem li = ...
li.File.SaveBinary(data);
Когда я запускаю этот код, я получаю:
Microsoft.SharePoint.SPException: The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again. ---> System.Runtime.InteropServices.COMException (0x8102006D): The security validation for this page is invalid. Click Back in your Web browser, refresh the page, and try your operation again.
at Microsoft.SharePoint.Library.SPRequestInternalClass.PutFile(String bstrUrl, String bstrWebRelativeUrl, Object varFile, PutFileOpt PutFileOpt, String bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Object varTimeCreated, Object varTimeLastModified, Object varProperties, String bstrCheckinComment, UInt32& pdwVirusCheckStatus, String& pVirusCheckMessage)
at Microsoft.SharePoint.Library.SPRequest.PutFile(String bstrUrl, String bstrWebRelativeUrl, Object varFile, PutFileOpt PutFileOpt, String bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Object varTimeCreated, Object varTimeLastModified, Object varProperties, String bstrCheckinComment, UInt32& pdwVirusCheckStatus, String& pVirusCheckMessage)
--- End of inner exception stack trace ---
at Microsoft.SharePoint.Library.SPRequest.PutFile(String bstrUrl, String bstrWebRelativeUrl, Object varFile, PutFileOpt PutFileOpt, String bstrCreatedBy, String bstrModifiedBy, Int32 iCreatedByID, Int32 iModifiedByID, Object varTimeCreated, Object varTimeLastModified, Object varProperties, String bstrCheckinComment, UInt32& pdwVirusCheckStatus, String& pVirusCheckMessage)
at Microsoft.SharePoint.SPFile.SaveBinary(Byte[] file, String checkInComment, Boolean checkRequiredFields, Boolean bIsMigrate, Boolean bIsPublish, SPUser modifiedBy, DateTime timeLastModified, SPVirusCheckStatus& virusCheckStatus, String& virusCheckMessage)
at Microsoft.SharePoint.SPFile.SaveBinary(Byte[] file, Boolean checkRequiredFields, Boolean bIsMigrate, Boolean bIsPublish, SPUser modifiedBy, DateTime timeLastModified)
at Microsoft.SharePoint.SPFile.SaveBinary(Byte[] file, Boolean checkRequiredFields)
at Microsoft.SharePoint.SPFile.SaveBinary(Byte[] file)
at TestClass.UploadFile()
Я запускаю этот код в форме, размещенной на том же сайте, что и sharepoint, и пользователь, который запускает код, может загрузить файл вручную просто отлично. Нужно ли сначала удалить файл? Проверить это?