vb.net附件上传函数

 vb.net附件上传函数,请大家指正

Private Function SaveImages() As System.Boolean
        '遍历File表单元素
        Dim files As System.Web.HttpFileCollection = System.Web.HttpContext.Current.Request.Files
        Dim FilePath, newpath As String
        Dim ls_sql As String
        Dim fileName, fileExtension As System.String
        '状态信息
        Dim strMsg As New System.Text.StringBuilder("上传的文件分别是:<hr color=red>")
        Dim iFile As System.Int32
        Try
            For iFile = 0 To files.Count - 1
                '检查文件扩展名字
                Dim postedFile As System.Web.HttpPostedFile = files(iFile)
                fileName = System.IO.Path.GetFileName(postedFile.FileName)
                If Not (fileName = String.Empty) Then
                    fileExtension = System.IO.Path.GetExtension(fileName)
                    strMsg.Append("上传的文件类型:" + postedFile.ContentType.ToString() + "<br>")
                    strMsg.Append("客户端文件地址:" + postedFile.FileName + "<br>")
                    strMsg.Append("上传文件的文件名:" + fileName + "<br>")
                    strMsg.Append("上传文件的扩展名:" + fileExtension + "<br><hr>")
                    '可根据扩展名字的不同保存到不同的文件夹
                    postedFile.SaveAs(System.Web.HttpContext.Current.Request.MapPath("attach/") + Me.tsubjectid.Text + fileName)
                    FilePath = Server.MapPath("attach/img/") + fileName
                    newpath = "http://" + Context.Request.Url.Host + context.Request.ApplicationPath + "/knowledge/attach" + "/" + Me.tsubjectid.Text + fileName + ""
                    newpath = newpath.Replace("/", "/")
                    'new_path.Text = newpath
                End If
                If (fileName = String.Empty) Then
                    msgbox(Me, "请添加附件!")
                    Exit Function
                End If
                Dim put_file As System.Int32
                ls_sql = "insert into knowledge_main_attach(accname,accpath,tsubjectid) "
                ls_sql += "values ('" & fileName & "','" & newpath & "','" + Me.tsubjectid.Text + "')"
                With New data_deal
                    If (.ExcuteSql(ls_sql) < 0) Then
                        msgbox(Me, " 附件没有成功!")
                    End If
                End With
            Next
            strStatus.Text = strMsg.ToString()
            Return True
        Catch Ex As System.Exception
            strStatus.Text = Ex.Message
            Return False
        End Try
    End Function 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值