我在网站集中部署了webpart。
此Web部件尝试读取文档库中文档的内容。它在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
答案 0 :(得分:1)
我有同样的问题......原来这是鬼。我可以在文档库中看到该文件(在本例中为xslt),我可以在Manage All Content中看到它,但是当我使用URL导航到IIS时,IIS无法提供文件。我是服务器上的管理员,所以它不应该是权限问题。
我只是通过重新上传文件(相同的名称和属性)解决了这个问题 - 突然我的System.Runtime.InteropServices.COMException(0x81070211):无法打开文件错误消失了。
放弃它,让我知道它是否适合你。
富
答案 1 :(得分:0)
两件事:
或者只使用以下代码(从我的头脑中)
byte[] content = file.OpenBinary();
答案 2 :(得分:0)
在打开之前尝试检出文件。同时处理上面提到的流。