You're Browsing As A Guest! Register Now... |
||
|
Become a VB.NET Expert!
Join 415,715 VB.NET Programmers for FREE! Get instant access to thousands
of VB.NET experts, tutorials, code snippets, and more! There are 716 people online right now.Registration is fast and FREE... Join Now!
|
||
Page 1 of 1
How to clear content of text file ?
#2
Re: How to clear content of text file ?
Posted 30 July 2008 - 12: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
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
#3
Re: How to clear content of text file ?
Posted 30 July 2008 - 02: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
hope this helps
vbnetskywalker
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
#5
Re: How to clear content of text file ?
Posted 30 July 2008 - 03:31 AM
vbnetskywalker, 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
hope this helps
vbnetskywalker
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.
#7
Re: How to clear content of text file ?
Posted 30 July 2008 - 03:45 AM
narmer93, 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
Page 1 of 1


Reply





MultiQuote








|