Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to execute a file

How to execute a file

Scheduled Pinned Locked Moved C#
csharpjsontutorialquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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#

    M M 2 Replies Last reply
    0
    • L Lost User

      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#

      M Offline
      M Offline
      Mazdak
      wrote on last edited by
      #2

      Check for Process.Start() and ProcessStartInfo classin MSDN. Mazy "Improvisation is the touchstone of wit." - Molière

      J 1 Reply Last reply
      0
      • M Mazdak

        Check for Process.Start() and ProcessStartInfo classin MSDN. Mazy "Improvisation is the touchstone of wit." - Molière

        J Offline
        J Offline
        Jonathan Slenders
        wrote on last edited by
        #3

        Thanks But if the filetype is not registered an error occur. Can i view the 'Open With...' dialog

        H 1 Reply Last reply
        0
        • J Jonathan Slenders

          Thanks But if the filetype is not registered an error occur. Can i view the 'Open With...' dialog

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Use ProcessStartInfo and set UseShellExecute and ErrorDialog both to true:

          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

          1 Reply Last reply
          0
          • L Lost User

            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#

            M Offline
            M Offline
            Mike Clark
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups