NewsFeed   -
KỸ THUẬT LẬP TRÌNH
S  M  L
Asp.net Read - Write - Create Html file - VB
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)
- 06/03/2011
Search:
NGHỆ THUẬT - PHIM - ẢNH

HÌNH ẢNH ĐẸP

Photo

Album: Cảnh Đẹp Việt Nam
< July 2011 >
Sun Mon Tue Wed Thu Fri Sat
26 27 28 29 30 1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31 1 2 3 4 5 6
More... (All Collections)
H2O NEWS

Everything Meaning To You!

Email: [email protected]

Website: emty.org

Liên hệ

Đặt làm trang chủ

@