在SharePoint 2010中阅读文档时遇到ComException
我在网站集中部署了webpart。
该webpart尝试读取文档库中文档的内容。 它在SharePoint 2007中工作正常。但这在SharePoint 2010中不起作用。如果文档大小很小,则它的工作正常。 否则我会得到以下异常。
Microsoft.SharePoint.SPException: Cannot open file "Document library/MyDoc-FAQ.doc". ---> System.Runtime.InteropServices.COMException (0x81070211): Cannot open file "Document library/MyOffice-FAQ.doc". at Microsoft.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) --- End of inner exception stack trace --- at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx) 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.OpenBinaryStream() at MyComp.Plugin.Office.MyOffice.handleEdit(HtmlTextWriter writer, NameValueCollection querystring)Message isCannot open file "Document library/MyDoc-FAQ.doc". source is Microsoft.SharePoint
示例代码
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;
}
}
文件大小超过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
我有这个相同的问题......原来这是一个鬼。 我可以在文档库(在这种情况下是xslt)中看到该文件,并且可以在“管理所有内容”中看到它,但是当我使用URL导航到文件时,IIS不会提供该文件。 我是服务器上的管理员,所以它不应该是权限问题。
我只是通过重新上传文件(相同的名称和属性)来解决问题 - 突然我的System.Runtime.InteropServices.COMException(0x81070211):无法打开文件错误消失了。
给它,让我知道它是否适合你。
丰富
两件事情:
或者,只需使用下面的代码(从我的头顶开始)
byte[] content = file.OpenBinary();
尝试在打开之前检出文件。 如上所述处理流。
链接地址: http://www.djcxy.com/p/57809.html上一篇: getting ComException while reading the document in SharePoint 2010