473,772 Members | 3,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(csvl ine)
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 6715
why not just delete it and recreate it?

"Poppy" <pa**********@N OSPAMthemedialo unge.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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(csvl ine)
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**********@N OSPAMthemedialo unge.com> wrote in message
news:#1******** ******@TK2MSFTN GP09.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(csvl ine)
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******** ******@TK2MSFTN GP10.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**********@N OSPAMthemedialo unge.com> wrote in message
news:#1******** ******@TK2MSFTN GP09.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(csvl ine)
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(csvl ine)
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**********@N OSPAMthemedialo unge.com> wrote in message
news:#N******** *****@TK2MSFTNG P11.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******** ******@TK2MSFTN GP10.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**********@N OSPAMthemedialo unge.com> wrote in message
news:#1******** ******@TK2MSFTN GP09.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(csvl ine)
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
2215
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
4813
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 codes, the "str1" is one text line , in fact. I want replace "str1" (the whole line) with the "str3". In my case, "str3" is shooter than "str1", But I will get some strange code that can not be
6
2382
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 222233334444. I am not sure how to acheive it PS.This application will run on Pocket Pc 2003
6
41965
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 original file and no temp file since the file is 1. on a network resource 2. pretty big 3. accessed by plenty of clients. Copying the file or reading everything into an array and then writing it back using the StreamWriter would lock the file...
22
4192
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. How can I delete the node from DOM in other way? Thanks.
2
12360
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 contents of the file using FILE operations. (not by using iostream, of c++) ex: fprintf Thanks,
6
4159
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 issue is I'm deleting the table in chunks, like so: WHILE (V_NO_DATA = 0) DO DELETE FROM
24
7564
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 the folder but I get the error message when the procedure attempts to delete the folder selected in the BrowseforFolderbyPath function. How can I get it to delete the folder that the user has selected in the Browse for Folder dialog?
29
5344
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 the delete button selected row wants to delete. My problem is(If i delete the first row, its say undefined and change the value is 0) pls check my program. <%pathdefiner = "../"%> <!--#include file="../connection/connector.asp" -->...
0
9620
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10261
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10104
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.