Home All Groups Group Topic Archive Search About

Richtextbox SaveFile Release

Author
7 Dec 2006 1:56 PM
Morrigan
Hello,

I am using the following code to add text to a RichTextBox:
    rtfLog.AppendText("File not Found: " & MyPath & MySubPath & "\" &
ArtikelTempStr & ".pdf" & Chr(10)):


Next step is to save the Richtextbox.text as file with the following
code:
    rtfLog.SaveFile(ErrorDir & "\" & LogFileName & ".log",
RichTextBoxStreamType.PlainText)

The file is created and is exactly as I want it, but...
When I hit the execute button on the form again, the file is locked
(being used by another process).
If I restart the program the file is released and it can be
overwritten< but thet is NOT my intention, the program will work 24/7
an may not have to be restarted every time it has don something.

Can anyone tell me what i can do to release the file and re-use or
delete the file?

I hope anyone of you out there has a solution or workaround for me.

Thanks in advance.

Author
7 Dec 2006 10:04 PM
iwdu15
i, myself, like to stay away from those "SaveAllText" methods in files. I
prefer to use a FileStream and StreamWriter objects....

Dim fs As New System.IO.FileStream("C:\Log.txt", FileAccess.Append,
FileMode.Write)      ''This is off the top of my head....it could be
FileMode.Append also...

Dim sw As New System.IO.StreamWriter(fs)

Dim s As String = "Stuff Here"

sw.WriteLine(s)

sw.Close()
fs.Close()

hope this helps
--
-iwdu15