i have a button, and when clicked, i want it to make a file "c:\hello.txt"
then rename it to "hello.doc"
and finally, run it
thanks
Printable View
i have a button, and when clicked, i want it to make a file "c:\hello.txt"
then rename it to "hello.doc"
and finally, run it
thanks
*BUMP*
You probably want to look into the File object and its associated methods:
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemiofileclasstopic.htm
Copious examples are off that page.
i did, but file.open doesnt work
is there any other way?
Not sure what you should do if the cut-and-paste examples in the help don't work. They do for me ;) Take a closer look at the examples.
Edit: Woops, I didn't point you to any cut/paste demos did I. Here ya go.
ms-help://MS.VSCC/MS.MSDNVS/vblr7/html/vastmopen.htm
ms-help://MS.VSCC/MS.MSDNVS/vblr7/html/vafctclose.htm
ms-help://MS.VSCC/MS.MSDNVS/vbcn7/html/vbconProcessingFiles.htm
ill try it as soon as i get home
but.. does anyone know why "file.open" doesnt work? because i really need to use this
thanks
I didn't check out the links but what do you want to put in the file?
You can use a filestream for most anything:
VB Code:
'if you are just going to rename it then you might as well just call it .doc in the first place 'renaming it doesn't format it any different Dim fs As System.IO.FileStream = New System.IO.FileStream("c:\hello.doc", System.IO.FileMode.OpenOrCreate) Dim sw As New System.IO.StreamWriter(fs) sw.WriteLine("Write a line of text here.") sw.Close() fs.Close() 'to start it in the associated program System.Diagnostics.Process.Start("c:\hello.doc")
Or if you want to save some typing you can add a couple of imports at the top above the form class and then write it like this:
VB Code:
'imports at top Imports System.IO Imports System.Diagnostics 'if you are just going to rename it then you might as well just call it .doc in the first place 'renaming it doesn't format it any different Dim fs As FileStream = New FileStream("c:\hello.doc", FileMode.OpenOrCreate) Dim sw As New StreamWriter(fs) sw.WriteLine("Write a line of text here.") sw.Close() fs.Close() 'to start it in the associated program Process.Start("c:\hello.doc")
ok, let me reexplain this
when button 1 is pressed, make a file "c:\hello.txt"
then print this text in the file:
" line 1
line 2
line3"
and thats it
i have no idea why i cant use "File.Open"
maybe someone can tell me why?
thanks again
Ok if you like the File.Open function so much then you can use it but it does the samething as the constructor I used for the filestream. Notice the return value in the IDE intellisense.
VB Code:
'Dim fs As System.IO.FileStream = New System.IO.FileStream("c:\hello.doc", System.IO.FileMode.OpenOrCreate) Dim fs As System.IO.FileStream = File.Open("c:\hello.doc", System.IO.FileMode.OpenOrCreate) Dim sw As New System.IO.StreamWriter(fs) sw.WriteLine("Write a line of text here.") sw.Close() fs.Close() 'to start it in the associated program System.Diagnostics.Process.Start("c:\hello.doc")
Working with files got a bit of a work over in .NET but trust me its much better this way.
its not that i like file.open so much, its that i dont see any other way of doing it
btw.. it still says file is not declared
WOOHOO
nm the question
i figured out why file.open doesnt work :)
thanks everyone