带文件上传功能的录入页面

假定有一个员工表,结构如下:

希望生成一个下图所示的页面,让用户此页面增加员工:

HttpRequest事件代码很简单:

Select Case e.Path
    Case "AddNew.htm"
        If e.PostValues.Count = 0 AndAlso e.Files.Count = 0 Then
            Dim sb As New StringBuilder
            sb.AppendLine("<form enctype='multipart/form-data' action='AddNew.htm' method='post'
id='form1' name='form1'>")
            sb.AppendLine(
"
姓名: <input name='xm' id='xm'><br/><br/>")
            sb.AppendLine(
"
部门: <input name='bm' id='bm'><br/><br/>")
            sb.AppendLine(
"
职务: <input name='zw' id='zw'><br/><br/>")
            sb.AppendLine(
"
学历: <input name='xl' id='xl'><br/><br/>")
            sb.AppendLine(
"
照片: <input type='file' name='zp' id='zp' multiple><br/><br/>")
            sb.AppendLine(
"<input Type='submit' name='Sumbit' id='Sumbit' value='
确定'>")
            sb.AppendLine("</form>")
            e.WriteString(sb.ToString)
        Else
            Dim dr As DataRow = DataTables(
"
员工").AddNew()
            Dim inms() As String = {"xm","bm","zw","xl"} '
输入框名称数组
            Dim cnms() As String =
{"
姓名","部门","职务","学历"} '列名数组,注意列名和输入框必须一一对应,位置不能错乱
            For i As Integer = 0 To inms.Length -1
                dr(cnms(i)) = e.PostValues(Inms(i)) 
            Next
            If  e.Files.ContainsKey("zp") Then
                dr(
"
照片") = e.Files("zp")(0)
                e.SaveFile("zp", e.Files("zp")(0), ProjectPath & "Attachments\" & e.Files("zp")(0))
            End If
           
dr.Save()
            Dim sb As New StringBuilder
            sb.AppendLine(
"
增加记录成功! <br/><br/>")
            sb.AppendLine(
"<a href='AddNew.htm'>
继续增加</a>")
            e.WriteString(sb.ToString)
       
End If
End
Select

上面的代码,用一个页面"AddNew.htm"完成了录入网页的生成,数据和文件的接收与 保存,以及记录增加成功后反馈页面的生成。


本页地址:http://www.foxtable.com/mobilehelp/topics/0034.htm