troubleshooting Question

How do I get the following code to work for Excel 2010?

Avatar of Michael Sterling
Michael SterlingFlag for United States of America asked on
C#Microsoft ExcelASP.NET
2 Comments1 Solution316 ViewsLast Modified:
for some reason i couldn't get the code (included below) to work for Microsoft Excel 2010. I had to save the spread sheet into a 97 - 2003 format and then it worked. how do i get this to work for microsoft excel 2010, just incase. or for 2007 for that matter? the error i got was "file not in expected format" which is pretty self explanatory but i'd still like to get it to function for the later versions of excel if possible...
protected void UpLoadFile_Click(object sender, EventArgs e)
        System.Uri uri1 = new Uri(@"C:\src\StudyTimeTrackerPrimeI\Data\QUStudentInfo.xlsx");
        Uri relativeUri = uri1.MakeRelativeUri(uri1);
        OleDbConnection _con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source="+@"C:\src\StudyTimeTrackerPrimeI\Data\QUStudentInfo.xls;Extended Properties=Excel 12.0");

            System.Data.DataTable _tab = new System.Data.DataTable();
            System.Data.DataTable _SheetTable = new System.Data.DataTable();
            _SheetTable = _con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);

            for (int Sheet = 0; Sheet < _SheetTable.Rows.Count; Sheet++)
                OleDbCommand _com = new OleDbCommand("SELECT * FROM [" + _SheetTable.Rows[Sheet][2].ToString() + "]", _con);
                OleDbDataAdapter _dap = new OleDbDataAdapter(_com);


                string _Meesage = string.Empty;
                for (int x = 0; x < _tab.Rows.Count; x++)
                    for (int y = 0; y < _tab.Columns.Count; y++)
                        _Meesage += _tab.Rows[x][y].ToString() + ",";

                    _Meesage += "\r\n";

                string _FileName = _SheetTable.Rows[Sheet][2].ToString();
                _FileName = _FileName.Replace("$", "");
                //_log.SuccessLoggingFileExcel(_FileName, _Meesage, Desitnation);
            // _log.SuccessLogging("UFL", "Mesage from the Success Logging From the user");  

            //return "Successessfully Parsed";

        catch (Exception ex)
            //Logging _lo = new Logging();
            //_log.LogErrorLog("Exception", ex);
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros