Public Class conn
Function WriteFile(ByVal strText As String, ByVal strContent As String, ByVal strAuthor As String)
Dim path As String = HttpContext.Current.Server.MapPath("news/")
Dim code As Encoding = Encoding.GetEncoding("gb2312")
Dim temp As String = HttpContext.Current.Server.MapPath("news/text.html")
Dim sr As StreamReader
sr = StreamReader.Null
Dim sw As StreamWriter
sw = StreamWriter.Null
Dim str As String = ""
Try
sr = New StreamReader(temp, code, True)
str = sr.ReadToEnd()
Catch ex As Exception
HttpContext.Current.Response.Write(ex.Message)
HttpContext.Current.Response.End()
sr.Close()
End Try
Dim htmlfilename As String = DateTime.Now.ToString("yyymmddhhmmss") + ".html"
str = str.Replace("ShowArticle", strText)
str = str.Replace("biaoti", strText)
str = str.Replace("content", strContent)
str = str.Replace("author", strAuthor)
Try
sw = New StreamWriter(path + htmlfilename, False, code)
sw.Write(str)
sw.Flush()
Catch ex As Exception
HttpContext.Current.Response.Write(ex.Message)
HttpContext.Current.Response.End()
Finally
sw.Close()
End Try
Return True
End Function
Function WriteFile(ByVal strText As String, ByVal strContent As String, ByVal strAuthor As String)
Dim path As String = HttpContext.Current.Server.MapPath("news/")
Dim code As Encoding = Encoding.GetEncoding("gb2312")
Dim temp As String = HttpContext.Current.Server.MapPath("news/text.html")
Dim sr As StreamReader
sr = StreamReader.Null
Dim sw As StreamWriter
sw = StreamWriter.Null
Dim str As String = ""
Try
sr = New StreamReader(temp, code, True)
str = sr.ReadToEnd()
Catch ex As Exception
HttpContext.Current.Response.Write(ex.Message)
HttpContext.Current.Response.End()
sr.Close()
End Try
Dim htmlfilename As String = DateTime.Now.ToString("yyymmddhhmmss") + ".html"
str = str.Replace("ShowArticle", strText)
str = str.Replace("biaoti", strText)
str = str.Replace("content", strContent)
str = str.Replace("author", strAuthor)
Try
sw = New StreamWriter(path + htmlfilename, False, code)
sw.Write(str)
sw.Flush()
Catch ex As Exception
HttpContext.Current.Response.Write(ex.Message)
HttpContext.Current.Response.End()
Finally
sw.Close()
End Try
Return True
End Function
本文介绍了一个用于ASP.NET应用程序中的文件写入功能,该功能能够将指定的文本内容及作者信息写入到HTML文件中,并通过替换模板文件中的占位符实现动态内容填充。
1602

被折叠的 条评论
为什么被折叠?



