Sharepoint问题将文件保存在文档库中的现有文件上

时间:2009-01-16 19:44:09

标签: sharepoint moss

我在文档库中有一个现有文档,我试图用代码覆盖该文件:

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在同一站点中托管的表单上运行此代码,运行代码的用户可以手动上传文件。我需要先删除文件吗?看看吧?

3 个答案:

答案 0 :(得分:2)

尝试此操作来修复它:

SPSecurity.RunWithElevatedPrivileges(delegate
{
  using (SPSite elevSite = new SPSite(currentWeb.Site.ID))
  {
    using (SPWeb elevWeb = elevSite.OpenWeb(currentWeb.ID))
    {
      elevWeb.AllowUnsafeUpdates = true;
      // ...
    }
  }
}

答案 1 :(得分:1)

我明白了。我在SPSecurity.RunWithElevatedPrivileges块中进行调用,导致它失败。我发现这很有趣,因为你会认为使用已经过时的权限运行会有更多的访问权限。

答案 2 :(得分:0)

尝试此操作以删除错误“此页面的安全验证无效。在Web浏览器中单击”返回“,刷新页面,然后再次尝试操作。”

http://sharepointhelps.wordpress.com/2008/08/05/the-security-validation-for-this-page-is-invalid-click-back-in-your-web/

谢谢,

  • Ashish Chotalia