473,386 Members | 1,943 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 6676
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: ajikoe | last post by:
Hello, If I use os.remove(fileName), does it always assure that the code will move to the next code only if the fileName is deleted completely? Pujo
8
by: Dong Ge | last post by:
Hi! I am a beginner of C. I want to delete some characters or a whole line in a text file. I have tried the "fprintf", "fputs", "fwrite", but no one of them can run rightly. In the below...
6
by: Percy NG | last post by:
Hi ... I have text file contain such data 1111222233334444 i need delete particlar char without load all data into memory says delete 1st-5th char ..then the data in text file should...
6
by: tomtown.net | last post by:
Hello I'm trying to get a single line removed from a text file using a search pattern (pretty simple: if line contains "NODE1") -> remove line). To achieve this I's like to operate with only the...
22
by: Cylix | last post by:
I have a 4row x 1col table, I would like to drop all the content of row three. Since Mac IE5.2 does not suppport deleteRow method, I have also try to set the innerHTML=''; but it does not work. ...
2
by: arunperi | last post by:
Hi All, I am using FILE (fprintf) operations to write into a specified file. Later, at a specific point i need to delete the contents of the file. Can anyone suggest how i can delete the...
6
by: jefftyzzer | last post by:
Friends: Let's say I'd like perform a delete, but before I delete, I'd like to export the target rows. I could use an export whose SELECT clause references the OLD TABLE of a DELETE, but the...
24
by: biganthony via AccessMonster.com | last post by:
Hi, I have the following code to select a folder and then delete it. I keep getting a Path/File error on the line that deletes the actual folder. The line before that line deletes the files in...
29
by: shivasusan | last post by:
Hi! I can add rows with inputs to my HTML table dynamically using DOM, but I cannot remove selected rows. In fact, every row contains a Delete button. So, user selects the rows to remove, clicks...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.