472,143 Members | 1,155 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

delete contents of text file

I use the following code to append a line of text to a text file :

Dim myFILENAME As String = Server.MapPath("/ABACUS/cvdocs/" & fileName)
Dim objStreamWriter As StreamWriter
objStreamWriter = File.AppendText(myFILENAME)
objStreamWriter.WriteLine(csvline)
objStreamWriter.Close()

The code works fine but I need to be a ble to delete the entire contents of
the file as well and I cant figure it out.

How can I open a text file and clean it out ?

Thanks in Advance

Nov 18 '05 #1
6 6607
why not just delete it and recreate it?

"Poppy" <pa**********@NOSPAMthemedialounge.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
I use the following code to append a line of text to a text file :

Dim myFILENAME As String = Server.MapPath("/ABACUS/cvdocs/" & fileName)
Dim objStreamWriter As StreamWriter
objStreamWriter = File.AppendText(myFILENAME)
objStreamWriter.WriteLine(csvline)
objStreamWriter.Close()

The code works fine but I need to be a ble to delete the entire contents of the file as well and I cant figure it out.

How can I open a text file and clean it out ?

Thanks in Advance

Nov 18 '05 #2
Just create an empty text file and overwrite the existing one.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Poppy" <pa**********@NOSPAMthemedialounge.com> wrote in message
news:#1**************@TK2MSFTNGP09.phx.gbl...
I use the following code to append a line of text to a text file :

Dim myFILENAME As String = Server.MapPath("/ABACUS/cvdocs/" & fileName)
Dim objStreamWriter As StreamWriter
objStreamWriter = File.AppendText(myFILENAME)
objStreamWriter.WriteLine(csvline)
objStreamWriter.Close()

The code works fine but I need to be a ble to delete the entire contents of the file as well and I cant figure it out.

How can I open a text file and clean it out ?

Thanks in Advance

Nov 18 '05 #3
If I can add lines to a textfile I dont know why I cant empty it.
I am already deleting it and recreating it bit I was wondering if there was
another solution.

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:uq**************@TK2MSFTNGP10.phx.gbl...
Just create an empty text file and overwrite the existing one.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Poppy" <pa**********@NOSPAMthemedialounge.com> wrote in message
news:#1**************@TK2MSFTNGP09.phx.gbl...
I use the following code to append a line of text to a text file :

Dim myFILENAME As String = Server.MapPath("/ABACUS/cvdocs/" & fileName)
Dim objStreamWriter As StreamWriter
objStreamWriter = File.AppendText(myFILENAME)
objStreamWriter.WriteLine(csvline)
objStreamWriter.Close()

The code works fine but I need to be a ble to delete the entire contents

of
the file as well and I cant figure it out.

How can I open a text file and clean it out ?

Thanks in Advance


Nov 18 '05 #4
Poppy,
You can open the file in overwrite mode using FileStream instead of
stream writer.
Try
http://msdn.microsoft.com/library/de...ClassTopic.asp
Poppy wrote:
I use the following code to append a line of text to a text file :

Dim myFILENAME As String = Server.MapPath("/ABACUS/cvdocs/" & fileName)
Dim objStreamWriter As StreamWriter
objStreamWriter = File.AppendText(myFILENAME)
objStreamWriter.WriteLine(csvline)
objStreamWriter.Close()

The code works fine but I need to be a ble to delete the entire contents of
the file as well and I cant figure it out.

How can I open a text file and clean it out ?

Thanks in Advance


--
Regards,
Dilip Krishnan
dilipkrish at msn. com
Nov 18 '05 #5
The simplest solution is NOT to delete the file, but simply create it. Sorry
if I wasn't clear on that point. It isn't necessary to delete it; creating
it will overwrite.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Poppy" <pa**********@NOSPAMthemedialounge.com> wrote in message
news:#N*************@TK2MSFTNGP11.phx.gbl...
If I can add lines to a textfile I dont know why I cant empty it.
I am already deleting it and recreating it bit I was wondering if there was another solution.

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:uq**************@TK2MSFTNGP10.phx.gbl...
Just create an empty text file and overwrite the existing one.

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Poppy" <pa**********@NOSPAMthemedialounge.com> wrote in message
news:#1**************@TK2MSFTNGP09.phx.gbl...
I use the following code to append a line of text to a text file :

Dim myFILENAME As String = Server.MapPath("/ABACUS/cvdocs/" & fileName) Dim objStreamWriter As StreamWriter
objStreamWriter = File.AppendText(myFILENAME)
objStreamWriter.WriteLine(csvline)
objStreamWriter.Close()

The code works fine but I need to be a ble to delete the entire
contents of
the file as well and I cant figure it out.

How can I open a text file and clean it out ?

Thanks in Advance



Nov 18 '05 #6
Thanks Guys.

You've been a great help.
Nov 18 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

14 posts views Thread by ajikoe | last post: by
8 posts views Thread by Dong Ge | last post: by
6 posts views Thread by Percy NG | last post: by
6 posts views Thread by tomtown.net | last post: by
22 posts views Thread by Cylix | last post: by
2 posts views Thread by arunperi | last post: by
6 posts views Thread by jefftyzzer | last post: by
24 posts views Thread by biganthony via AccessMonster.com | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.