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!
 
I would verify that the file path in the file is valid:
If File.Exists("fullyqualifiedpathnamehere") Then Process.Start("fullyqualifiedpathnamehere")
 
this is true juggalobrotha I would too, but maybe wrongly I assumed that mordicaii would have already handled this. :)
 
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:

VB.NET:
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:
VB.NET:
   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
 
Invisionsoft said:
..CreateSubKey(..).SetValue(..)
to avoid memory leaks change to:
VB.NET:
dim key = ..CreateSubKey(..)
key.SetValue(..)
key.Close()
 
VB.NET:
   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
VB.NET:
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
 
Thank You all who helped, with some tweaking it worked THANK YOU
 
Back
Top