Question Open correct software with file

Status
Not open for further replies.

kaiser

Member
Joined
Dec 11, 2007
Messages
16
Programming Experience
1-3
Hello,

I have an issue where one type of file can be opened by three different executables. I was using the System.Diagnostics.Process.Start() to open the software or the actual file and that works fine.

However I have added a user control that allows the user to select which software they want to open the particular file selected. How do I, in VB.NET, make the application open the file with the selected software, if it is possible?

Thank you in advance!

Kyle
 
VB.NET:
	Private Sub uxNotepad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
	Handles uxNotepad.Click

		Process.Start("notepad", "C:\Temp\MyFile.txt")

	End Sub

VB.NET:
	Private Sub uxWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
	Handles uxWord.Click

		Process.Start("winword", "C:\Temp\MyFile.txt")

	End Sub

Alternativele you can specify the FileName and Agruments in the StartInfo like this:

VB.NET:
		Dim p As New Process
		p.StartInfo.FileName = "winword"
		p.StartInfo.Arguments = "C:\Temp\MyFile.txt"
		p.Start()
 
Thank you for your reply...

What if the executable for the three different applications have the same name, but are stored in different directories?

Is there away to do something like this?
VB.NET:
Dim p As New Process
p.StartInfo.FileName = "C:\Program Files\App1\App1.exe"
p.StartInfo.Arguments = "C:\Temp\MyFile.xxx"
p.Start()

Dim p As New Process
p.StartInfo.FileName = "C:\Program Files\App2\App2.exe"
p.StartInfo.Arguments = "C:\Temp\MyFile.xxx"
p.Start()

Dim p As New Process
p.StartInfo.FileName = "C:\Program Files\App3\App3.exe"
p.StartInfo.Arguments = "C:\Temp\MyFile.xxx"
p.Start()
 
Let me clear up a little more of what I am trying to do...

I have three different applications with the same executable name in different directories. These applications are all capable of opening the same file extension. I have a user control that allows the user to select what application they want to use to open the file selected, however I cannot figure out any VB to make this work. It would be similar the built in Windows "Open With..." dialog, which I could use, but I do not want the user to be able to choose from a different list of programs. Some code is listed below of the idea I am trying to get across.

Please help if you know how to solve my Issue! Thank you in advance!

VB.NET:
 Dim p As New Process
        If x = y Then
            p.StartInfo.FileName = "C:\Program Files\App1\App1.exe"
            p.StartInfo.Arguments = "C:\Temp\MyFile.xxx"
            p.Start()
        ElseIf x = z Then
            p.StartInfo.FileName = "C:\Program Files\App2\App2.exe"
            p.StartInfo.Arguments = "C:\Temp\MyFile.xxx"
            p.Start()
        Else
            p.StartInfo.FileName = "C:\Program Files\App3\App3.exe"
            p.StartInfo.Arguments = "C:\Temp\MyFile.xxx"
            p.Start()
        End If
 
Status
Not open for further replies.
Back
Top