Unable to Read Exported excel file

Mar 21, 2012 at 12:23 PM

I have used this tool for reading Excel and Validate data.

The problem is unable to read excel file which are exported from another page.

There is a functionality to export excel from c# .net and I have written follwoing code.


 string fileName = "Test.xls";
 #region Clean up Response Object
 Response.Buffer = true;
 Response.Charset = "";
 Response.ContentEncoding = System.Text.Encoding.Default;

 #region Set the response mime type for excel
   Response.AddHeader("content-disposition", string.Format("attachment; filename={0}.xls", fileName));
   Response.ContentType = "application/vnd.xls;charset=utf-8";//"application/ms-excel";

  #region Create a string writer
    using (StringWriter sw = new StringWriter())
       using (HtmlTextWriter htw = new HtmlTextWriter(sw))
          // instantiate a datagrid  
         GridView gvTreatmentResults = new GridView();
         gvTreatmentResults.DataSource = this.resultsDS.Tables[0];

 After then , I tried to upload expored file, but was not able to read. ExcelDatareader object is not null, but all properties are null. IsValid and Read() and ASDataSet().

Can you please do the needful. As I have to complete it on trgent basis.


Thanks in Advance.