Save as Html

Graham

Member
Joined
Feb 17, 2007
Messages
13
Programming Experience
5-10
At the moment I open a html file into a RTB, when I save it I use the code below but this only saves it as a text file with a Html extension I want it to be saved as an Html file.
VB.NET:
Dim strExt As String
        strExt = System.IO.Path.GetExtension(currentFile)
        strExt = strExt.ToUpper()
        Select Case strExt
            Case ".RTF"
                rtbText.SaveFile(currentFile, RichTextBoxStreamType.RichText)
            Case ".DOC"
                ' Copy the contents of the Richtextbox to the clipboard and keep it's formating
                Clipboard.SetText(rtbText.Rtf, TextDataFormat.Rtf)
                objWord = CreateObject("Word.Application")
                objTempDoc = objWord.Documents.Add
                With objTempDoc
                    .Content.Paste()
                    .Activate()
                    .Save()
                End With
                objWord.Quit()
            Case Else
                Dim txtWriter As System.IO.StreamWriter
                txtWriter = New System.IO.StreamWriter(currentFile)
                txtWriter.Write(rtbText.Text)
                txtWriter.Close()
                txtWriter = Nothing
                rtbText.SelectionStart = 0
                rtbText.SelectionLength = 0
        End Select
 
A html file is just a plain text file with .html/.htm extension.
 
code looks fine to me, although instead of doing a select case on the extension of the file name, i would simply use the FilterIndex property of the SaveFileDialog instead (assuming one is used)
 
Back
Top