getting ComException while reading the document in SharePoint 2010
I deployed webpart in the site collection.
This webpart tried to read the content of the document in the document library. Its work fine in SharePoint 2007. But this is not working in SharePoint 2010. If the document size is small, its working fine. otherwise i am getting the following Exception.
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
Sample Code
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;
}
}
Error occurs when the file size is exceed 100kb. Please help me to overcome this issue
In the SharePoint log i got the following exception
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
I had this same issue... turned out it was a ghost. I could see the file in the document library (xslt's in this case) and I could see it in Manage All Content, but IIS would not serve the file when i navigated to it using the URL. I am admin on the server so it should not be a permissions issue.
I solved the issue simply by re-uploading the file (same name and properties) - suddenly my System.Runtime.InteropServices.COMException (0x81070211): Cannot open file error went away.
Give it go and let me know if it worked for you.
Rich
Two things:
Alternatively just use the following code (from the top of my head)
byte[] content = file.OpenBinary();
Try checking out the file prior to opening. Also dispose of the stream as mentioned above.
链接地址: http://www.djcxy.com/p/57810.html上一篇: 问题设置和读取Cookie,PHP