Open / Save file Dialog

Apr 10 2006 4:08 PM
Hi All,

I just writed a wordpad in VB.NET2003 and the problem I have is to keep format as color, indentation,fonts on save and open file. Any help appresiated.

Thanks all in advance


Here Is the code:

//Open File===================================

Private Sub mmMenuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmMenuFileOpen.Click



'Try and Catch Error
Try
If Me.ofdOpen.ShowDialog() = DialogResult.OK Then
Dim fs As New FileStream(ofdOpen.FileName, FileMode.Open, FileAccess.Read)
Dim m_streamReader As New StreamReader(fs, System.Text.Encoding.ASCII)
ofdOpen.InitialDirectory = ".\My Documents"
' Read to the file using StreamReader class
m_streamReader.BaseStream.Seek(0, SeekOrigin.Begin)


' Read each line of the stream and parse until last line is reached
Me.mainWindow.Text = ""
Dim strLine As String = m_streamReader.ReadLine()
While Not (strLine Is Nothing)
Me.mainWindow.Text += strLine + ControlChars.Lf
strLine = m_streamReader.ReadLine()
End While
' Close the stream
m_streamReader.Close()
End If
Catch em As Exception
System.Console.WriteLine(em.Message.ToString())
End Try

End Sub
=====================================================

\\Save File


Private Sub mmMenuFileSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmMenuFileSave.Click


'SaveFileDialog

Dim sfdSave As New SaveFileDialog
sfdSave.Filter = "Rich Text Format(*.rtf)|*.rtf|Text File(*.txt)|*.txt|Word Document(*.doc)|*.doc|Text Document -MS-DOS Format(*.txt)|*.txt|Unicode Text Document(*utf)|*.utf|All Files|*.*"
sfdSave.FilterIndex = 2 sfdSave.InitialDirectory = ".\My Documents"

sfdSave.OverwritePrompt = True
If sfdSave.ShowDialog() = DialogResult.OK Then
Dim stream As System.IO.Stream
stream = sfdSave.OpenFile()
Console.WriteLine(sfdSave.FileName)
If Not (stream Is Nothing) Then
Dim sw As New System.IO.StreamWriter(stream)
sw.WriteLine(Me.mainWindow.Rtf)
sw.Close()
stream.Close()
End If
End If

End Sub

================================================== ==