Anupama Singh
on click of button how to open excel file in c#
By Anupama Singh in Windows Forms on May 06 2008
  • rama vadde
    Sep, 2012 18

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

    • 0
  • murali krishna
    Apr, 2012 4

    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

    • 0
  • May, 2008 6

    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

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS