Ch13-02-02.aspx 如何创建文件
Sub Button1_Click(Obj As Object, E As EventArgs)
If Trim(File1.Text) = "" then
Show1.InnerHTML = "请输入文件名称!"
Exit Sub
End If
Show1.InnerHtml = ""
Dim FileName As String = File1.Text
Dim Files As New FileInfo(FileName)
Dim blnRet As Boolean
blnRet = FileExists(Files, FileName)
If BlnRet = False Then
Show1.InnerHTML = Show1.InnerHTML & "文件不存在,可以创建文件!"
CreateFile(Files, FileName)
Else
Show1.InnerHTML = Show1.InnerHTML & "文件已经存在,无法创建文件!"
End if
End Sub
' 检查文件是否存在
Function FileExists(Files As FileInfo, _
FileName As String) As Boolean
If Files.Exists Then
FileExists = True
Else
FileExists = False
End if
End Function
' 创建文件
Sub CreateFile(Files As FileInfo, FileName As String)
Files = New FileInfo(FileName)
Dim Fs As FileStream = Files.Create()
Fs.Close()
End Sub
文件名称:
Runat="Server" />
OnClick="Button1_Click" Runat="Server" />
BorderColor="#FF0000" Runat="Server" />