Groups | Blog | Home
all groups > vb.net upgrade > may 2004 >

vb.net upgrade : how to insert text to a file?



barbara_dave NO[at]SPAM yahoo.com
5/4/2004 11:10:09 AM
Hi all

I need to write a message line to a text file. Could someone give me a
sample code for how to use "seek" method?

barbara_dave NO[at]SPAM yahoo.com
5/4/2004 3:59:04 PM
Yes. I did look at the Help file, but I still can't understand it.
What I need is:

I open a text file and write something into the file, and I need to
set a file pointer before I close it. When I second time open the
file, I need to write a string at the first time pointer position.
Could someone give me some sample code?

hirf-spam-me-here NO[at]SPAM gmx.at
5/4/2004 8:12:33 PM
* barbara_dave@yahoo.com (barbara) scripsit:
[quoted text, click to view]

Did you already put the caret on 'Seek' and press F1?

--
Herfried K. Wagner [MVP]
barbara_dave NO[at]SPAM yahoo.com
5/5/2004 9:06:34 AM
[quoted text, click to view]

Even I don't close the file, I still can't get the position. My code
is in the following:

dim myFileStream As FileStream
dim myFileWriter As StreamWriter
dim Location as long

myFileWriter.writeline("Line1")
myFileWriter.write("Line2") 'I need to add a string in here later
Location = myFileWriter.BaseStream.seek(0, seekorigin.current)
muFileWriter.write(controlchars.crlf)
myFileWriter.writeline("Line3")
.....

'Now I want to go back to the end of Line2 to append " a string"
myFileWriter.basestream.seek(Location, seekorigin.begin)
myFileWriter.write(" a string")


For some reasons, Location value always is 0, and " a string" always
added to the end of the file instead of Line2. Where I am wrong???
Please give me some instructions!!!

hirf-spam-me-here NO[at]SPAM gmx.at
5/5/2004 11:37:18 AM
* barbara_dave@yahoo.com (barbara) scripsit:
[quoted text, click to view]

The file pointer will be lost when closing the file. You will have to
store the position somewhere else.

--
Herfried K. Wagner [MVP]
AddThis Social Bookmark Button