生成静态页

来源:百度文库 编辑:神马文学网 时间:2024/04/27 15:34:35
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim mydb As New AccessDb
Dim myReader As OleDb.OleDbDataReader
‘读取模板布局html代码
Dim myTemplate As String
myReader = mydb.ExecuteSqlStrDetails("select * from Portal_templates where templateId=1")
If myReader.Read Then
myTemplate = myReader("TemplateBody")
End If
myReader.Close()
‘读取文章信息
Dim myArticleBody As String
myReader = mydb.ExecuteSqlStrDetails("select * from portal_articles where articleid=2")
If myReader.Read Then
myArticleBody = myReader("content")
End If
myReader.Close()
‘组合成要生成静态页
Dim myHtml As String
myHtml = Replace(myTemplate, "‰ArticleContent‰", myArticleBody)
‘生成静态页
Dim path As String = Server.MapPath(".") & "\article2.htm"
If File.Exists(path) = False Then
‘ Create a file to write to.
Dim sw As StreamWriter = File.CreateText(path)
sw.Write(myHtml)
sw.Flush()
sw.Close()
End If
Response.Write("Success!")
End Sub