Skip to content

Instantly share code, notes, and snippets.

@alemik
Last active February 1, 2023 08:03
Show Gist options
  • Select an option

  • Save alemik/a0322a1a8cba6f28491561c4c69c540e to your computer and use it in GitHub Desktop.

Select an option

Save alemik/a0322a1a8cba6f28491561c4c69c540e to your computer and use it in GitHub Desktop.
Open file from process
private void OpenFile()
{
if(string.IsNullOrEmpty(FilePath)) return;
var extension = Path.GetExtension(FilePath);
bool isExcel = extension == ".xlsx" ^ extension == ".xls";
if (!isExcel) return;
try
{
using Process process= new Process();
process.StartInfo.UseShellExecute = true;
process.StartInfo.FileName = "excel";
process.StartInfo.Arguments = FilePath;
process.Start();
}
catch (Exception ex)
{
MessageBox.Show("Can not oper Excel file");
Debug.Print(ex.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment