vb.net的文本保存和读取代码,用于保存网站详情页内容用.,这样就减轻数据库的ntext字段的存储压力,使数据库在访问,执行的时候更轻,更快。
''' <summary>
''' 读取内容
''' </summary>
Function DataContent( ID As String, Optional Content As String = "") As String
Try
Dim Path As String = AppPath & "\UpFile\News\"
If IO.Directory.Exists(Path) = False Then IO.Directory.CreateDirectory(Path) '文件夹是否存在,不存在而创建
Path &= ID & ".txt"
If Content <> "" Then '保存
IO.File.WriteAllText(Path, Content, Encoding.UTF8)
ElseIf IO.File.Exists(Path) = True Then '文本存在
Return IO.File.ReadAllText(Path) '读取文本内容
End If
Catch ex As Exception
End Try
Return ""
End Function
读取代码时候,Content 为空就是,Content 有内容表示要进行存储更新内容。