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);
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
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