delete contents of text file

Discussion in 'ASP .Net' started by Poppy, Feb 11, 2004.

  1. Poppy

    Poppy Guest

    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
    Poppy, Feb 11, 2004
    #1
    1. Advertising

  2. why not just delete it and recreate it?

    "Poppy" <> wrote in message
    news:%...
    > 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
    >
    >
    >
    Michael Ramey, Feb 11, 2004
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:#...
    > 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
    >
    >
    >
    Kevin Spencer, Feb 11, 2004
    #3
  4. Poppy

    Poppy Guest

    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" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:#...
    > > 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
    > >
    > >
    > >

    >
    >
    Poppy, Feb 11, 2004
    #4
  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" <> wrote in message
    news:#...
    > 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" <> wrote in message
    > news:...
    > > 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" <> wrote in message
    > > news:#...
    > > > 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
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Kevin Spencer, Feb 11, 2004
    #5
  6. Poppy,
    You can open the file in overwrite mode using FileStream instead of
    stream writer.
    Try
    http://msdn.microsoft.com/library/d...ef/html/frlrfSystemIOFileStreamClassTopic.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
    Dilip Krishnan, Feb 11, 2004
    #6
  7. Poppy

    Poppy Guest

    Thanks Guys.

    You've been a great help.
    Poppy, Feb 11, 2004
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy Chapman

    Load contents of a text file into a text box

    Jeremy Chapman, Aug 15, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    758
    Tommy
    Aug 15, 2003
  2. Don Adams
    Replies:
    1
    Views:
    594
    Martin Honnen
    Mar 5, 2004
  3. jen
    Replies:
    0
    Views:
    721
  4. Kamarulnizam Rahim
    Replies:
    4
    Views:
    217
    Robert Klemme
    Jan 28, 2011
  5. newzguy

    How to Delete File Contents

    newzguy, Aug 7, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    124
    J├╝rgen Exner
    Aug 7, 2004
Loading...

Share This Page