----------------------------------------
Imports System.io
Public Class CreateFile
Inherits System.Web.UI.Page
#Region " Web 窗体设计器生成的代码 "
'该调用是 Web 窗体设计器所必需的。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
Protected WithEvents TextBox2 As System.Web.UI.WebControls.TextBox
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
'注意: 以下占位符声明是 Web 窗体设计器所必需的。
'不要删除或移动它。
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: 此方法调用是 Web 窗体设计器所必需的
'不要使用代码编辑器修改它。
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'在此处放置初始化页的用户代码
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strTitle, strContent, strFolder As String
Dim i As Integer
Dim Arrjj As Array
strTitle = TextBox1.Text
strContent = TextBox2.Text
Arrjj = Split(strContent, "[page]")
Dim strFileName As String = Now.ToShortDateString.ToString & "_" & Now.Hour.ToString & "_" & Now.Minute.ToString & "_" & Now.Second.ToString & "_" & System.Guid.NewGuid.ToString.Substring(1, 3)
For i = 0 To UBound(Arrjj)
Dim strPath As String = Server.MapPath("News\" & Now.ToShortDateString.ToString & "\")
' 判断上传目录是否存在,不存在就建立
If (Not Directory.Exists(strPath)) Then
Directory.CreateDirectory(strPath)
End If
Try
Dim sw As StreamWriter = New StreamWriter(strPath & strFileName & "_" & i & ".shtml", False, System.Text.Encoding.Default) 'GetEncoding("gb2312")
' Add some text to the file.
sw.Write("<html>" & Chr(13))
sw.Write("<head>" & Chr(13))
sw.Write("<meta http-equiv='Content-Type' content='text/html; charset=gb2312'>" & Chr(13))
sw.Write("<title>这是测试用的</title>" & Chr(13))
sw.Write("<style type=""text/css"">" & Chr(13))
sw.Write("<!--" & Chr(13))
sw.Write("body {" & Chr(13))
sw.Write(" font-size: 12px;" & Chr(13))
sw.Write("}" & Chr(13))
sw.Write("-->" & Chr(13))
sw.Write("</style>" & Chr(13))
sw.Write("</head>" & Chr(13))
sw.Write("<body>" & Chr(13))
'sw.Write("<!--#include file=""t.htm""--> " & Chr(13))
Dim str As String = Arrjj(i)
str = str.Replace(Chr(13), "<br>")
str = str.Replace(Chr(32), " " & Chr(32))
sw.Write("<center>" & strTitle & "</center><hr width=98% size=1>")
sw.Write(str & Chr(13))
'sw.WriteLine("header for the file.")
'sw.WriteLine("-------------------")
' Arbitrary objects can also be written to the file.
If UBound(Arrjj) - 1 > 1 Then
If i = 0 Then
sw.Write("<br><a href=" & strFileName & "_" & i + 1 & ".shtml>下一页</a> 当前第<font color=red>" & i + 1 & "</font>页/共<font color=red>" & UBound(Arrjj) + 1 & "</font>页")
ElseIf i > 0 And i < UBound(Arrjj) Then
sw.Write("<br><a href=" & strFileName & "_" & i - 1 & ".shtml>上一页</a> <a href=" & strFileName & "_" & i + 1 & ".shtml>下一页</a> 当前第<font color=red>" & i + 1 & "</font>页/共<font color=red>" & UBound(Arrjj) + 1 & "</font>页")
Else
sw.Write("<br><a href=" & strFileName & "_" & i - 1 & ".shtml>上一页</a> 当前第<font color=red>" & i + 1 & "</font>页/共<font color=red>" & UBound(Arrjj) + 1 & "</font>页")
End If
End If
sw.Write("<br>The date is: ")
sw.WriteLine(DateTime.Now)
sw.Write("</body>" & Chr(13))
sw.Write("</html>" & Chr(13))
sw.Close()
Response.Write("OK")
Catch ex As Exception
Response.Write(ex.Message)
End Try
Next
Response.Redirect("/News/" & Now.ToShortDateString.ToString & "/" & strFileName & "_0.shtml")