I have one excel file uploaded in document library of office 365 site.I want to read this excel file using c# as we read in farm solution using following code.

            using (SPSite site = new SPSite("siteurl"))
                using (SPWeb web = site.RootWeb)
                    SPFile file = web.Folders["Shared Documents"].Files["test.xlsx"];
                    StreamReader reader = new StreamReader(file.OpenBinaryStream());
                    contents = reader.ReadToEnd();

But this code is not working in sandbox solution. It will give error for OpenBinaryStream function during build step.Actually I want to create sharepoint list from excel file in office 365 programmatically. I have also tried manual step from this link http://blog.blksthl.com/2014/01/15/office-365-guide-series-create-a-new-list-from-an-excel-spreadsheet/ but when i click on import button it gives this error : An unexpected error has occurred.(-2147221005).

  • I know SPFile.OpenBinaryStream() is not available in Sandboxed solutions in 2010, so I don't think it'll work with 2013. As for the app in your link, you'll have to contact the developer. – wjervis Apr 18 '14 at 19:20

Your Answer

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

Browse other questions tagged or ask your own question.