在SharePoint 2010中读取文档时获取ComException

在SharePoint 2010中读取文档时获取ComException,sharepoint,sharepoint-2010,Sharepoint,Sharepoint 2010,我在网站集中部署了webpart 此Web部件试图读取文档库中文档的内容。它在SharePoint 2007中工作得很好。但这在SharePoint 2010中不起作用。如果文档大小较小,则其工作正常。否则我将得到以下异常 文件大小超过100kb时出错。请帮助我克服这个问题 在SharePoint日志中,我得到了以下异常 at Microsoft.SharePoint.CoordinatedStreamBuffer.SPBackgroundSqlFileFiller.StartNext

我在网站集中部署了webpart

此Web部件试图读取文档库中文档的内容。它在SharePoint 2007中工作得很好。但这在SharePoint 2010中不起作用。如果文档大小较小,则其工作正常。否则我将得到以下异常


文件大小超过100kb时出错。请帮助我克服这个问题

在SharePoint日志中,我得到了以下异常


   at Microsoft.SharePoint.CoordinatedStreamBuffer.SPBackgroundSqlFileFiller.StartNextFill(SPInterval iNext)     at Microsoft.SharePoint.CoordinatedStreamBuffer.SPBackgroundFileFiller.DoNextOperation()     at Microsoft.SharePoint.CoordinatedStreamBuffer.SPBackgroundFileFiller.Fill()     at Microsoft.SharePoint.CoordinatedStreamBuffer.SPCoordinatedStreamBufferFactory.CreateFromDocParams(SqlSession session, Guid guidSiteId, Int32 grfDocFlags, Int64 cbContent, SPChunkedArray`1 rgbContent, Byte[] rgbRbsId, Guid guidDoc, Int32 iInternalVersion, Int32 pageSize, Boolean bStartFilling)     at Microsoft.SharePoint.CoordinatedStreamBuffer.SPCoordinatedStreamBufferFactory.CreateFromDocumentRowset(SqlSession session, Object[] row, SPDocumentBindRequest& dbreq, SPDocumentBindResults& dbres)     at Micr... 1cc7f9da-32ed-4446-aaa7-8bc6dd4cd635
10/14/2010 19:27:18.77* w3wp.exe (0x1F28)                           0x1ED0  SharePoint Foundation           Database                        fa46    High        ...osoft.SharePoint.Library.SPRequestInternalClass.GetFileAsStream(String bstrUrl, String bstrWebRelativeUrl, Boolean bHonorLevel, Byte iLevel, OpenBinaryFlags grfob, String bstrEtagNotMatch, String& pEtagNew, String& pContentTagNew)     at Microsoft.SharePoint.Library.SPRequest.GetFileAsStream(String bstrUrl, String bstrWebRelativeUrl, Boolean bHonorLevel, Byte iLevel, OpenBinaryFlags grfob, String bstrEtagNotMatch, String& pEtagNew, String& pContentTagNew)     at Microsoft.SharePoint.SPFile.GetFileStreamCore(OpenBinaryFlags openOptions, String etagNotMatch, String& etagNew, String& contentTagNew)     at Microsoft.SharePoint.SPFile.GetFileStream(OpenBinaryFlags openOptions, String etagNotMatch, String& etagNew, String& contentTagNew)     at Microsoft.SharePoint.SPFile.OpenBinary(SPOpenBinary...  1cc7f9da-32ed-4446-aaa7-8bc6dd4cd635
10/14/2010 19:27:18.77* w3wp.exe (0x1F28)                           0x1ED0  SharePoint Foundation           Database                        fa46

两件事:

  • 确保您已处理流()
  • 您是否尝试从流中获取file.length
  • 或者,只需使用以下代码(从我的头顶)


    尝试在打开文件之前签出该文件。同样,如上所述处理流。

    我也有同样的问题。。。原来是鬼。我可以在文档库(本例中为xslt)中看到该文件,也可以在“管理所有内容”中看到该文件,但当我使用URL导航到该文件时,IIS不会提供该文件。我是服务器上的管理员,因此这不应该是权限问题

    我只需重新上传文件(相同的名称和属性)就解决了这个问题-突然我的System.Runtime.InteropServices.COMException(0x81070211):无法打开文件错误消失了

    放开它,让我知道它是否对你有用


    里奇

    Thnak u Muhimbi,但我也试过了。它不起作用。我也遇到了同样的问题如何克服这个问题?请帮助我,我不知道,除了我推荐的。尝试单步执行代码,查看每个步骤中变量是否包含合理的信息。当文件大小超过100kb时,会发生错误。我被困在这个问题上了。请帮助我克服这个问题我对同一个问题还有一个悬而未决的问题:有人知道如何解决这个问题吗?
    
    
      using (SPSite siteCol = new SPSite(siteurl))
                {
                    using (SPWeb oWebsite = siteCol.OpenWeb())
                    {
                        oWebsite.AllowUnsafeUpdates = true;
    
                        SPFolder folder = oWebsite.GetFolder(folderurl);
                        SPFileCollection files = folder.Files;
    
                        SPFile file = files[filename];
                         Stream stream = file.OpenBinaryStream();
                         byte[] content = null;
                         BinaryReader reader = new BinaryReader(stream);
    
                         content = reader.ReadBytes((int)file.Length);//If the document size is higher, i am getting exception
    
                         oWebsite.AllowUnsafeUpdates = false;
    
                      }
    
    
                }    
    
    
       at Microsoft.SharePoint.CoordinatedStreamBuffer.SPBackgroundSqlFileFiller.StartNextFill(SPInterval iNext)     at Microsoft.SharePoint.CoordinatedStreamBuffer.SPBackgroundFileFiller.DoNextOperation()     at Microsoft.SharePoint.CoordinatedStreamBuffer.SPBackgroundFileFiller.Fill()     at Microsoft.SharePoint.CoordinatedStreamBuffer.SPCoordinatedStreamBufferFactory.CreateFromDocParams(SqlSession session, Guid guidSiteId, Int32 grfDocFlags, Int64 cbContent, SPChunkedArray`1 rgbContent, Byte[] rgbRbsId, Guid guidDoc, Int32 iInternalVersion, Int32 pageSize, Boolean bStartFilling)     at Microsoft.SharePoint.CoordinatedStreamBuffer.SPCoordinatedStreamBufferFactory.CreateFromDocumentRowset(SqlSession session, Object[] row, SPDocumentBindRequest& dbreq, SPDocumentBindResults& dbres)     at Micr... 1cc7f9da-32ed-4446-aaa7-8bc6dd4cd635
    10/14/2010 19:27:18.77* w3wp.exe (0x1F28)                           0x1ED0  SharePoint Foundation           Database                        fa46    High        ...osoft.SharePoint.Library.SPRequestInternalClass.GetFileAsStream(String bstrUrl, String bstrWebRelativeUrl, Boolean bHonorLevel, Byte iLevel, OpenBinaryFlags grfob, String bstrEtagNotMatch, String& pEtagNew, String& pContentTagNew)     at Microsoft.SharePoint.Library.SPRequest.GetFileAsStream(String bstrUrl, String bstrWebRelativeUrl, Boolean bHonorLevel, Byte iLevel, OpenBinaryFlags grfob, String bstrEtagNotMatch, String& pEtagNew, String& pContentTagNew)     at Microsoft.SharePoint.SPFile.GetFileStreamCore(OpenBinaryFlags openOptions, String etagNotMatch, String& etagNew, String& contentTagNew)     at Microsoft.SharePoint.SPFile.GetFileStream(OpenBinaryFlags openOptions, String etagNotMatch, String& etagNew, String& contentTagNew)     at Microsoft.SharePoint.SPFile.OpenBinary(SPOpenBinary...  1cc7f9da-32ed-4446-aaa7-8bc6dd4cd635
    10/14/2010 19:27:18.77* w3wp.exe (0x1F28)                           0x1ED0  SharePoint Foundation           Database                        fa46
    
    
    byte[] content = file.OpenBinary();