1. Create Html file
'To Update an existing file, use:
Dim HTML As New StringBuilder()
'Dim NewLine As String = System.Environment.NewLine
HTML.AppendLine("")
HTML.AppendLine("")
HTML.AppendLine("")
HTML.AppendLine("")
HTML.AppendLine(myEditor.Text) 'This this the content of the HTML page
HTML.AppendLine("")
HTML.AppendLine("")
'Get a StreamWriter class that can be used to write to the file
Dim objStreamWriter As StreamWriter
objStreamWriter = File.AppendText(AutoFileName)
objStreamWriter.WriteLine(HTML)
'Close the stream
objStreamWriter.Close()
'** To create a new file, use:
Dim HTML As New StringBuilder()
'Dim NewLine As String = System.Environment.NewLine
HTML.AppendLine("")
HTML.AppendLine("")
HTML.AppendLine("")
HTML.AppendLine("")
HTML.AppendLine(myEditor.Text)
HTML.AppendLine("")
HTML.AppendLine("")
' Send as Textfile response
Dim MainPath As String = ConfigurationManager.AppSettings("MainPath") & "HtmlSources\"
Dim AutoFileName As String = Path.GetRandomFileName & Now.Minute.ToString & Now.Second.ToString
AutoFileName = Left(AutoFileName, AutoFileName.LastIndexOf(".")) & ".htm"
'Get a StreamWriter class that can be used to write to the file
Dim objStreamWriter As StreamWriter
objStreamWriter = File.AppendText(MainPath & AutoFileName)
objStreamWriter.WriteLine(HTML)
'Close the stream
objStreamWriter.Close()
2. Load HTML Page into editor container:
Dim BisString As String = ""
lblFileName.Text = .Item("htmFilename").ToString
Dim hFileName As String = ConfigurationManager.AppSettings("MainPath") & "HtmlSources\" & .Item("htmFilename").ToString
'Read HtmlContent
'If you need to control share permissions when creating a file you
'use FileStream with StreamReader
Dim MyFileStream As FileStream = New FileStream(hFileName, FileMode.Open, FileAccess.Read, FileShare.None)
Dim MyStreamReader As StreamReader = New StreamReader(MyFileStream)
BisString = MyStreamReader.ReadToEnd()
MyStreamReader.Close()
Me.myEditor.Text = BisString 'Put the entire HTML pgae into Editing area.
3. Display the HTML in an aspx page:
litHTML.Text = File.ReadAllText(htmlFile)
|