Opening an excel file from button click on a windows form

11,855

Probably you should just start the Excel file directly with property UseShellExecute to true, which is the default, and it will launch the default associated program, most likely Excel itself:

Process.Start(outputFilePath);

Another matter is why you are doing that Replace, but that's probably off-topic here.

Share:
11,855
sid
Author by

sid

Updated on June 14, 2022

Comments

  • sid
    sid almost 2 years
    private void btnOpenReport_Click(object sender, EventArgs e)
    {  
        if (System.IO.File.Exists(outputFilePath))
        {
            Process.Start(new ProcessStartInfo("excel.exe", " /select, " + outputFilePath.Replace("\\\\", "\\")));
         }
    }