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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to openfile an existing file in notepad 1

Status
Not open for further replies.

peebman2000

Programmer
Nov 28, 2006
30
US
Hey guys, i'm trying to create a button in my app to open a text file from the c: drive in notepad. I'm getting errors with the code I found below. Does anyone know how this code I found works?

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim filename As String = "C:/newfile.txt"
Dim open As New OpenFileDialog()
open.ShowDialog()
filename = open.FileName()

process.start("notepad.exe", filename)

End Sub
 
For some reason I'm getting errors 1. " type 'openfiledialog' is not defined. 2. Name 'process' is not declared. I'm importing system.io, I don't know why i'm getting errors and its not working for me. Any other suggestions.
 
Works for me, too (VS 2003).

But since you set the filename to "C:/newfile.txt", why would you show the openfiledialog?

Another suspect is the "open" object name. It might be a (hidden) reserved word.
In addition (not sure about this), try adding:
Imports System.Windows.Forms.FileDialog
 
I commented out the show opefile dialog, it now says Process is not declared as my error. I tried importing windows.dorms.filedialog and I get another error. I don't know, any other suggestion on how to open an existing text file in notepad?
 
I know you said that you were importing System.IO, but try:

[tt]
System.IO.Process.Start("notepad.exe", filename)
[/tt]

by the way I think you should also change [tt]"C:/newfile.txt"[/tt] to [tt]"C:\newfile.txt"[/tt]


Hope this helps.

[vampire][bat]
 
Hey guys thanks for the all the help and suggestions, but I got it. I found some other code online and it worked. I imported System.diagnostic.Process. It opens my file in notepad. Earthandfire you had a good Idea. Thanks again.

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click ' button to open converted file
Dim filename As String = "C:/newfile.txt"

'Dim open As New OpenFileDialog()
'open.ShowDialog()
'filename = open.FileName()
'call("notepad.exe",filename)
System.Diagnostics.Process.Start("notepad.exe", filename)

End Sub
 
Sorry, my mistake. You are right, it is System.Diagnostics, not System.IO. Glad you sorted it though.

[vampire][bat]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top