8 Replies - 53320 Views - Last Post: 03 August 2008 - 11:09 AM Rate Topic: -----

#1 itayzoro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-July 08

How to clear content of text file ?

Post icon  Posted 29 July 2008 - 10:44 PM

HI

I got text file lets say : take1.txt and after i export a database i want to clear the content an rewrite , What i dont wont is to delete the file a write it again
Is This A Good Question/Topic? 0
  • +

Replies To: How to clear content of text file ?

#2 narmer93  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 317
  • Joined: 13-March 08

Re: How to clear content of text file ?

Posted 30 July 2008 - 01:28 AM

well, i was ging to do this
but this may work only on a .doc file and may not work on a .txt file
first ,the form will contain an empty richtextbox and u can make it invisible to not make trouble with u
u will choose a rich textbox cuz it can be saved to a .doc file with the code
richtextbox1.savetext(".doc location")
so the rchtxtbox will be empty and when u press the button that contains the above code ,the .doc file will be empty
GOOD LUCK
Was This Post Helpful? 0
  • +
  • -

#3 vbnetskywalker  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 98
  • Joined: 08-June 08

Re: How to clear content of text file ?

Posted 30 July 2008 - 03:53 AM

hi there
there was some functions in VB6 for this kind of functionalities
and they're kept in VB.Net just for the compatibility
(I'm talking about 2003 ,I don't know about 2005 yet )

try this one

	Dim Filenum As Integer = FreeFile()
	FileOpen( Filenum , "c:\Test.txt", OpenMode.Output) 
	FileClose()




hope this helps

vbnetskywalker
Was This Post Helpful? 0
  • +
  • -

#4 narmer93  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 317
  • Joined: 13-March 08

Re: How to clear content of text file ?

Posted 30 July 2008 - 04:02 AM

hey are u talking about v32003,i think it is not vs.net cuz i heared that vs2005 is the first .net products
but i am not sure

This post has been edited by narmer93: 30 July 2008 - 04:03 AM

Was This Post Helpful? 0
  • +
  • -

#5 Smudge202  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 02-July 08

Re: How to clear content of text file ?

Posted 30 July 2008 - 04:31 AM

View Postvbnetskywalker, on 30 Jul, 2008 - 03:53 AM, said:

hi there
there was some functions in VB6 for this kind of functionalities
and they're kept in VB.Net just for the compatibility
(I'm talking about 2003 ,I don't know about 2005 yet )

try this one

	Dim Filenum As Integer = FreeFile()
	FileOpen( Filenum , "c:\Test.txt", OpenMode.Output) 
	FileClose()




hope this helps

vbnetskywalker


I believe that is for older versions than vs2005. With .net you tend to use streamwriters. There's some helpful information on streamwriters here:

http://www.startvbdo...es/default.aspx

You could perhaps combine that with a rich text box control to do what you need?

http://www.astahost....iles_t5286.html

Hope either of them help.
Was This Post Helpful? 0
  • +
  • -

#6 narmer93  Icon User is offline

  • D.I.C Regular

Reputation: 8
  • View blog
  • Posts: 317
  • Joined: 13-March 08

Re: How to clear content of text file ?

Posted 30 July 2008 - 04:38 AM

so u think my idea about using the richtextbox will work?but why does it work only for .doc files and doesn't work for .docx ot .txt files?
Was This Post Helpful? 0
  • +
  • -

#7 Smudge202  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 02-July 08

Re: How to clear content of text file ?

Posted 30 July 2008 - 04:45 AM

View Postnarmer93, on 30 Jul, 2008 - 04:38 AM, said:

so u think my idea about using the richtextbox will work?but why does it work only for .doc files and doesn't work for .docx ot .txt files?


I think using a richtextbox could provide a usable workaround, though I'm pretty sure the streamer should be able to be used to compare 'OriginalStream' with 'ModifiedStream' and delete lines and add lines as necessary, or even use the streamer to delete everything, write the deleted stream to the text file, and then write a second stream which contains the new data.

I just haven't found any example of that kind of stream work, possibly because it can't be done, or possibly because I'm not looking hard enough.

If it can't be done using (a) stream object(s) then its likely a rtf control will provide a workaround. Though at the same time, you may be able to do this using a text box. I imagine there's many ways, though the op is making it difficult by not letting us simply delete the file and create a new one :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#8 WayneSpangler  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 106
  • Joined: 22-March 08

Re: How to clear content of text file ?

Posted 30 July 2008 - 02:20 PM

If you are using vb 2005 or vb 2008 then you can use:
 My.Computer.FileSystem.OpenTextFileWriter("c:\Test.txt", False)


This post has been edited by WayneSpangler: 30 July 2008 - 02:21 PM

Was This Post Helpful? 0
  • +
  • -

#24 gbertoli3  Icon User is offline

  • DIC at Heart + Code
  • member icon

Reputation: 40
  • View blog
  • Posts: 1,162
  • Joined: 23-June 08

Re: How to clear content of text file ?

Posted 03 August 2008 - 11:09 AM

Why don't you try this
'Set the File to be written to & Write a blank document
System.IO.File.WriteAllText("take1.txt","")


Was This Post Helpful? 1

Page 1 of 1