Last active
February 1, 2023 08:03
-
-
Save alemik/a0322a1a8cba6f28491561c4c69c540e to your computer and use it in GitHub Desktop.
Open file from process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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