Quantcast
Channel: SharePoint 2010 - Setup, Upgrade, Administration and Operations forum
Viewing all articles
Browse latest Browse all 13778

upload and Read Excel from document library programatically in sharepoint 2010

$
0
0

Hi,

I have a requirement where on button click, programatically Ihave to upload an Excel (it could be .xls, .xlsx) file from user local machine to 'shared documents' library and read it (spreadsheets and all) and delete it once completed.

Here, Uploading and deleting to shared documents library code i have done.

Issue is with programatically reading uploaded excel file to 'shared documents' library. I tried some examples with OpenXml but getting error "data is corrupted" while reading stream.

excelSheets = new ExcelHelper().GetExcelSheets(file.fi);
                        SPFile _file = web.GetFile(string.Format("{0}/Shared Documents/" + _fileUrl, SPContext.Current.Site.RootWeb.Url));//("http://servername:1000/ExcelDocs//ExcelFile.xlsx");
                        Stream dataStream = file.OpenBinaryStream();
                        SpreadsheetDocument document = SpreadsheetDocument.Open(dataStream, false);
                        Workbook workbook = document.WorkbookPart.Workbook;

                        List<string> _sheets = new List<string>();
                        Sheets workSheets = workbook.Sheets;
                        foreach (Sheet s in workSheets)
                        {
                            _sheets.Add(s.Name);
                        }

Regards,

Rahul


Viewing all articles
Browse latest Browse all 13778

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>