3
Reply

on click of button how to open excel file in c#

Anupama Singh

Anupama Singh

May 06, 2008
18.1k
0

    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 vadde
    September 18, 2012
    0

    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

    murali krishna
    April 04, 2012
    0

    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

    May 06, 2008
    0