Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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)
   {
       base.ItemAdded(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);
   }
share|improve this question

migrated from programmers.stackexchange.com Aug 3 '11 at 21:30

This question came from our site for professional programmers interested in conceptual questions about software development.

add comment

2 Answers 2

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

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.