Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 15th, 2005, 5:16 PM   #11
brokenhope
Hobbyist Programmer
 
Join Date: Apr 2005
Posts: 126
Rep Power: 4 brokenhope is on a distinguished road
I ended up doing this how I didnt want to do it. I had to open the file stream and read stream, read through the file and generate a string containing the text that should be written. Close both strings, reopen the file stream, and start a write stream, this time with the mode being Create, so it deletes the old file and creates a new, then writes the string to the file, then closes it... It was the only way I could figure out that works... any better ideas?

        If System.IO.Directory.Exists(txtOpenFileDirectory.Text) Or txtOpenFileDirectory.Text = "" Then
            ' First Create the new text to write to the file
            Dim oFileStream As New System.IO.FileStream("elementalEditor.dat", IO.FileMode.Open)
            Dim oStreamReader As New System.IO.StreamReader(oFileStream)
            Dim iCount As Integer = 0
            Dim strEditFileText As String
            oStreamReader.BaseStream.Seek(0, IO.SeekOrigin.Begin)

            While oStreamReader.Peek <> -1
                ' Line 1 is the default open directory. 
                If iCount = 0 Then
                    strEditFileText = strEditFileText & txtOpenFileDirectory.Text & vbNewLine
                    oStreamReader.ReadLine()
                Else
                    strEditFileText = strEditFileText & oStreamReader.ReadLine() & vbNewLine
                End If
                iCount = iCount + 1
            End While

            oStreamReader.Close()
            oFileStream.Close()

            'Second reopen the stream and write the data
            oFileStream = Nothing
            oFileStream = New System.IO.FileStream("elementalEditor.dat", IO.FileMode.Create)
            Dim oStreamWriter As New System.IO.StreamWriter(oFileStream)
            oStreamWriter.Write(strEditFileText)
            oStreamWriter.Flush()
            oStreamWriter.Close()
            oFileStream.Close()
        Else
            ' Doesnt exist
            MsgBox("The default file open directory does not exist.", MsgBoxStyle.Exclamation)
        End If
brokenhope is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:16 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC