Open a file from a file

Mordicaii

New member
Joined
Jul 24, 2008
Messages
2
Programming Experience
1-3
Hello,

I have been hunting around on Google for the past hour looking for code on how to open a file from a file.

If you would, could you give code on how to do what notepad does. (you double click on a .txt file, it opens in notepad and displays the contents)

How would I do this?
All help is appreciated!


Thanks!
 

demausdauth

Well-known member
Joined
Mar 24, 2008
Messages
281
Location
Minnesota
Programming Experience
3-5
the quick way

Process.Start("fullyqualifiedpathnamehere")
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
I would verify that the file path in the file is valid:
If File.Exists("fullyqualifiedpathnamehere") Then Process.Start("fullyqualifiedpathnamehere")
 

demausdauth

Well-known member
Joined
Mar 24, 2008
Messages
281
Location
Minnesota
Programming Experience
3-5
this is true juggalobrotha I would too, but maybe wrongly I assumed that mordicaii would have already handled this. :)
 

Invisionsoft

Well-known member
Joined
Apr 20, 2007
Messages
64
Location
United Kingdom
Programming Experience
1-3
I got the impression that he/she wanted to edit the registry so when the user clicks a file inside a explorer folder, the exe is launched and the filename can be used, for example to show an image or put the contents into a RichTextBox.

Well if this is the case, I found a snippet from my app open ATM:

Code:
My.Computer.Registry.ClassesRoot.CreateSubKey(".xds").SetValue(Nothing, "xds", Microsoft.Win32.RegistryValueKind.String)
        My.Computer.Registry.ClassesRoot.CreateSubKey("xds\shell\open\command").SetValue("", "C:\DSGameMaker\DS Game Maker.exe" & _
       " ""%l"" ", Microsoft.Win32.RegistryValueKind.String)
This makes .xds files open with C:\DSGameMaker\DS Game Maker.exe

And this handles seeing if someone double clicked a file before your app opens:
Code:
   Dim toopen As String = ""
        For Each i As String In My.Application.CommandLineArgs
            toopen = i
        Next
        If Not toopen = "" Then
            openfile(toopen)
        Else
        End If
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
Code:
   Dim toopen As String = ""
        For Each i As String In My.Application.CommandLineArgs
            toopen = i
        Next
        If Not toopen = "" Then
            openfile(toopen)
        Else
        End If
Code:
For Each str As String In My.Application.CommandLineArgs
  'Looking for switches:
  Select Case str.ToLower.Trim
    Case "Whatever you're looking for"
  End Select

  'Check if file is passed in:
  If System.IO.File.Exists(str.Trim) Then
    'Save the file path after further validation is done
  End If
Next str
 

Mordicaii

New member
Joined
Jul 24, 2008
Messages
2
Programming Experience
1-3
Thank You all who helped, with some tweaking it worked THANK YOU
 
Top Bottom