c# - Export to Excel - Installing Office Customization in MVC4 -


i exporting excel file in mvc4 application.
excel

public class exporttoexcel : actionresult { public gridview excelgridview { get; set; } public string filename { get; set; } public int totalquantity; public decimal totalprice1; public string x1;  public exporttoexcel(gridview gv, string pfilename, int totalqty, decimal totalprice, string x) {   x1= x;   excelgridview = gv;   filename = pfilename;   totalquantity = totalqty;   totalprice1 = totalprice; }     public override void executeresult(controllercontext context)     {     httpcontext curcontext = httpcontext.current;     curcontext.response.clear();     curcontext.response.addheader("content-disposition", "attachment;filename=" + filename);     curcontext.response.charset = "";     curcontext.response.cache.setcacheability(httpcacheability.nocache);     curcontext.response.contenttype = "application/vnd.ms-excel";           stringwriter sw = new stringwriter();     htmltextwriter htw = new htmltextwriter(sw);     if (x1== "111")     {       htw.writeline("<html><head>");       //code logic       excelgridview.headerstyle.backcolor = color.yellow;       excelgridview.rendercontrol(htw);       htw.writeline("</body></html>");     }     else     {       htw.writeline("data");       excelgridview.rendercontrol(htw);     }     byte[] bytearray = encoding.ascii.getbytes(sw.tostring());     memorystream s = new memorystream(bytearray);     streamreader sr = new streamreader(s, encoding.ascii);     curcontext.response.write(sr.readtoend());     curcontext.response.end();     } } 

the below error occurs , excel file not opened.

error :  from: file:///d:/program files/microsoft visual studio 10.0/common7/ide/privateassemblies/microsoft.visualstudio.qualitytools.loadtestexceladdin.vsto did not succeed. 


mistake in code. should resolve error. ?
edit :
error occurs in ie. firefox , chrome opens excel file.

i added 3 files in local machine in location error specified.

microsoft.visualstudio.qualitytools.loadtestexceladdin.dll microsoft.visualstudio.qualitytools.loadtestexceladdin.dll.manifest microsoft.visualstudio.qualitytools.loadtestexceladdin 

it works fine , ie opens excel file.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -