Interviews3 answers
on click of button how to open excel file in c#
3 Answers
On GridView View ImageButton nClick Use This Code::::
ImageButton img = (ImageButton)sender;
GridViewRow row = (GridViewRow)img.NamingContainer;
System.Web.UI.WebControls.Label lblView = (System.Web.UI.WebControls.Label)row.FindControl("lblView");
string Invoice = lblView.Text;
Session["Invoice"] = Invoice;
string savePath = Server.MapPath("../InvoiceDetails/" + Session["Invoice"].ToString());
string programFiles = Environment.GetEnvironmentVariable("ProgramFiles");
const string excelRelativePath = @"Microsoft Office\Office12\excel.exe";
string excel = Path.Combine(programFiles, excelRelativePath);
ProcessStartInfo startInfo = new ProcessStartInfo(excel, savePath);
Process.Start(startInfo);
rama vaddePosted Sep 18, 2012, 12:52 AM EDT
Yes this piece of code worked fine for me.But when i uploaded the pages to server.......it didnt worked. Can you pls figure it out why it happened like that? in local it is fine. it wont work while we upload the page to server?
Code in btn click event:
System.Diagnostics.Process objDocProcess = new System.Diagnostics.Process();
objDocProcess.EnableRaisingEvents = false;
objDocProcess.StartInfo.FileName = Server.MapPath("~/Administration/GenerateMatrix.xls");
objDocProcess.Start();
Thanks in advance.
K.Murali Krishna
Code in btn click event:
System.Diagnostics.Process objDocProcess = new System.Diagnostics.Process();
objDocProcess.EnableRaisingEvents = false;
objDocProcess.StartInfo.FileName = Server.MapPath("~/Administration/GenerateMatrix.xls");
objDocProcess.Start();
Thanks in advance.
K.Murali Krishna
murali krishnaPosted Apr 4, 2012, 5:58 AM EDT
Using System.Diagnostics.Process, you can launch any file(xls/doc/htm).
Put the following code in Button click event.
===================================================
System.Diagnostics.Process objDocProcess = new System.Diagnostics.Process();
objDocProcess.EnableRaisingEvents = false;
objDocProcess.StartInfo.FileName = @"C:\ABCD.xls";
objDocProcess.Start();
===================================================
Thejus
thejus_raghavanPosted May 6, 2008, 5:48 AM EDT