Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opening an instance of Notepad 1

Status
Not open for further replies.

SteveShanks

Programmer
Nov 28, 2001
112
GB
HI Everyone

What is the best way to open a text file that exists on the disk within an instance of Notepad from VB.net?

Any pointers in the right direction much appreciated!

Thanks
Steve
 
You can use the shell command for a quick and simple way to do it. e.g.
Code:
Shell("C:\MyTextFile.txt")

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
You must define the program that will open the txt file, if you use the Shell() method. That method opens executable files better. Otherwize you'll get error message.

You should use this:

Code:
System.Diagnostics.Process.Start("c:\hello.txt")

Or put an import statement out of the form class, like...

Code:
Imports System.Diagnostics.Process

and finally...
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  Start("c:\hello.txt")
End Sub
 
Thanks guys

Got it going with

Shell("NOTEPAD.exe " & strFilePath, AppWinStyle.NormalFocus)

Cheers
Steve
 
Yes sorry that should have been the following for the above notepad example.
Code:
Shell("Notepad C:\MyTextFile.txt")
But I agree this maybe isn't the best way hence the "quick and simple way to do it".


----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
I use the Framework.
'Shell("Notepad " & """" & Filename & """", _
' AppWinStyle.MaximizedFocus, False)
Dim myProcess As New Process()
myProcess.StartInfo.FileName = "Notepad.exe"
myProcess.StartInfo.Arguments = Filename
myProcess.StartInfo.WindowStyle = _
ProcessWindowStyle.Maximized
myProcess.Start()


Compare Code
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top