I have a problem that involves reading contents of an Excel file after the excel file has been added to a document library in SharePoint 2010. Reading the file contents was easy on client machine with OleDB driver, but since the Sharepoint feature will be deployed on a 64 bit server, using that driver is out of the question.

My last approach has been to first read the file contents from the db (Every file in SP is stored as so, there is no real path to the file) into a byte array, save that byte array to file system and then read the file using functionality under Microsoft.Office.Interop.Excel namespace.

I'm stuck at writing the byte array onto system disc, with file permission errors (logged in as admin during the execution). Ignoring the file locking mechanism and cleanup, this is what i currently have:

       public override void ItemAdded(SPItemEventProperties properties)
       string pathToReadAndWrite = @"C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS";

       byte[] byteStream = properties.ListItem.File.OpenBinary();
       SPSecurity.RunWithElevatedPrivileges(() =>
               // Logged in as admin
               // UnAuthorizedAccessException, 
               // Access to the path 'C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS' is denied.
               File.WriteAllBytes(pathToReadAndWrite, byteStream);

       Application excel = new Application();

       Workbook excelWorkbook =
            excel.Workbooks.Open(pathToReadAndWrite, 0, true, 5, "", "",
            false, XlPlatform.xlWindows, "", true, false, 0, true, false, false);

       Workbooks workbooks = excel.Workbooks;

       Workbook workbook = workbooks.Open
           (pathToReadAndWrite, 0, false, 5, "", "", false, XlPlatform.xlWindows, "",
                true, false, 0, true, false, false);

What do you need to do with the Excel Workbook when opened? I think you might be able to solve your issue using the Excel Services API. Have a read here: http://msdn.microsoft.com/en-us/library/ms546696.aspx


I wonder whether you could use the 64bit drivers (http://www.microsoft.com/download/en/details.aspx?displaylang=en&id=20065).

We typically use a third party component (is not free but very easy to use) when working with Excel files like the one Aspose is selling (http://www.aspose.com/categories/.net-components/aspose.cells-for-.net/default.aspx).

I hope this helps. Kr., Bernd.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy