How to execute a file
-
how can i execute a file e.g. if i have a file c:\text.exe or d:\test.htm So if i have a textbox and the user enter the filelocation enter a filename. if it is an application, i want execute that application, if it is a document, i want execute the defeault program for reading that file in VB6 there was an execute API, i thougt Shellexecute But how can i do this in c#
-
how can i execute a file e.g. if i have a file c:\text.exe or d:\test.htm So if i have a textbox and the user enter the filelocation enter a filename. if it is an application, i want execute that application, if it is a document, i want execute the defeault program for reading that file in VB6 there was an execute API, i thougt Shellexecute But how can i do this in c#
-
Check for
Process.Start()
andProcessStartInfo
classin MSDN. Mazy "Improvisation is the touchstone of wit." - MolièreThanks But if the filetype is not registered an error occur. Can i view the 'Open With...' dialog
-
Thanks But if the filetype is not registered an error occur. Can i view the 'Open With...' dialog
Use
ProcessStartInfo
and setUseShellExecute
andErrorDialog
both totrue
:ProcessStartInfo info = new ProcessStartInfo();
info.FileName = myTextBox.Text;
info.UseShellExecute = true;
info.ErrorDialog = true;
Process.Start(info);Be sure to read the class documentation for additional members to see what other features exist.
Microsoft MVP, Visual C# My Articles
-
how can i execute a file e.g. if i have a file c:\text.exe or d:\test.htm So if i have a textbox and the user enter the filelocation enter a filename. if it is an application, i want execute that application, if it is a document, i want execute the defeault program for reading that file in VB6 there was an execute API, i thougt Shellexecute But how can i do this in c#
One way to do this is to use System.Diagnostics.Process... using System.Diagnostics; . . . // // opens an instance of notepad with the file c:\mytest.xsd // private void OpenTheFileInNotepad(string fileName) { Process.Start("notepad.exe",fileName); } see MSDN at: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDiagnosticsProcessClassTopic.asp