You are here:

C#/Excel data upload error

Advertisement


Question
Excel Error
Excel Error  
QUESTION: Hi Murat,
I am making an application in which I am downloading excel from website and uploading its data to my sql server database.

Now when I run code I am getting Error like, Exception from HRESULT: 0x800A03EC

I found that the problem is excel which I am opening has some unreadable data. I have attached an image of excel error.

This error is a reason for what I am getting Error in my code.

This is My C# Code :

 string path = MapPath("/MyFolder/File1.xls");
 var client = new WebClient();
 client.DownloadFile("Url for Excel File", path);

 Excel.Application xlApp = new Excel.Application();
 Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(path);

I am getting above error in xlApp.Workbooks.Open(path).

Help me for this error.

Thanks...

ANSWER: Hi there,

Code seems fine. Problem is probably about your file. Ensure your file is xls and not xlsx. Try to open manually with Excel and see if you get the same error.

Hope that helps,

Murat

---------- FOLLOW-UP ----------

QUESTION: Hi,

There is no problem with code or extension. Problem is with file. When I open file manually it shows error which I have shown above in image. I have to open file and save it again then it will upload data perfectly.

But I am downloading file from code and uploading data directly to database. So I cant do it manually.

Answer
Hi again,

If the problem is in excel file, you cannot read the file through code. First you have to check and fix the file. Once you are sure the file is correct and can be read, then you can read with code. I have no idea why your file cannot be read, there are tons of reasons for showing that message. File may not be uploaded correctly, is another extension, you may be using older version of excel than the file etc.

C#

All Answers


Answers by Expert:


Ask Experts

Volunteer


Murat Mehmet

Expertise

I can help with questions about desktop and web programming in C#, including SOAP, XML, database managing, custom controls, security etc.

Experience

I have been developing web and especially desktop applications in C# and VB.Net for almost 5 years. My programming life has begun with VB6 long time ago, so its about 8 years that I am in this business.

Organizations
Was in R & D for 2 years in a popular Turkish technology website: cyber-warrior.com

Education/Credentials
2011 Computer Engineering graduation in University of Trakia in Turkey.

©2016 About.com. All rights reserved.