Private Sub BtnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnUpload.Click
Dim postPath As String
Dim myFile As HttpPostedFile
Dim serverPath As String
Dim serverName As String
Dim tmpName, erroutput As String
Dim fileExtn As String If Not filUpload.PostedFile Is Nothing Then myFile = filUpload.PostedFile
Dim fnFileLen As Integer = myFile.ContentLength
If fnFileLen = 0 Then
erroutput = myinfo.Deal_Info("errstring", "Error Information", 14)
Page.RegisterStartupScript("1", "<script>" & erroutput & "</script>")
Exit Sub
End If
'Check the file !
Dim strExt As String() = New String(5) {".gif", ".jpg", ".jpeg", ".jpe", ".bmp", ".png"}
Dim strExtensions As String = System.IO.Path.GetExtension(myFile.FileName).Trim.ToLower
If (Array.IndexOf(strExt, strExtensions) = -1) Then
erroutput = myinfo.Deal_Info("errstring", "Error Information", 15)
Page.RegisterStartupScript("1", "<script>" & erroutput & "</script>")
Exit Sub
Else
errMsg.Text = ""
End If If myAttach(myFile, tmpDir) = False Then
Exit Sub
Else
erroutput = myinfo.Deal_Info("errstring", "Error Information", 16)
Page.RegisterStartupScript("1", "<script>" & erroutput & "</script>")
Exit Sub
End If
'System.IO.File.Move(imgFile.ImageUrl, Server.MapPath("dbimg/" & filename.Value))
'imgFile.ImageUrl = Server.MapPath("dbimg/" & filename.Value)
End If
End Sub '=================================================
Public Function myAttach(ByVal htpFile As HttpPostedFile, ByVal strSavePath As String) As Boolean
Dim tmpDir As String
Try
Dim saveFile As String
filename.Value = myRandom() & System.IO.Path.GetExtension(htpFile.FileName)
saveFile = txtPath.Value & filename.Value
While System.IO.File.Exists(saveFile)
filename.Value = myRandom() & System.IO.Path.GetExtension(htpFile.FileName)
saveFile = txtPath.Value & filename.Value
End While
htpFile.SaveAs(saveFile)
imgFile.ImageUrl = "tmp\" & filename.Value
'imgFile.ImageUrl = ResolveUrl(saveFile)
' errMsg.Text = "<b><font color=red>" & "Upload Success ! please Save" & "</font></b>"
Return True
Catch exp As Exception
errMsg.Text = exp.ToString()
Return False
End Try
End Function
'=================================================
Dim postPath As String
Dim myFile As HttpPostedFile
Dim serverPath As String
Dim serverName As String
Dim tmpName, erroutput As String
Dim fileExtn As String If Not filUpload.PostedFile Is Nothing Then myFile = filUpload.PostedFile
Dim fnFileLen As Integer = myFile.ContentLength
If fnFileLen = 0 Then
erroutput = myinfo.Deal_Info("errstring", "Error Information", 14)
Page.RegisterStartupScript("1", "<script>" & erroutput & "</script>")
Exit Sub
End If
'Check the file !
Dim strExt As String() = New String(5) {".gif", ".jpg", ".jpeg", ".jpe", ".bmp", ".png"}
Dim strExtensions As String = System.IO.Path.GetExtension(myFile.FileName).Trim.ToLower
If (Array.IndexOf(strExt, strExtensions) = -1) Then
erroutput = myinfo.Deal_Info("errstring", "Error Information", 15)
Page.RegisterStartupScript("1", "<script>" & erroutput & "</script>")
Exit Sub
Else
errMsg.Text = ""
End If If myAttach(myFile, tmpDir) = False Then
Exit Sub
Else
erroutput = myinfo.Deal_Info("errstring", "Error Information", 16)
Page.RegisterStartupScript("1", "<script>" & erroutput & "</script>")
Exit Sub
End If
'System.IO.File.Move(imgFile.ImageUrl, Server.MapPath("dbimg/" & filename.Value))
'imgFile.ImageUrl = Server.MapPath("dbimg/" & filename.Value)
End If
End Sub '=================================================
Public Function myAttach(ByVal htpFile As HttpPostedFile, ByVal strSavePath As String) As Boolean
Dim tmpDir As String
Try
Dim saveFile As String
filename.Value = myRandom() & System.IO.Path.GetExtension(htpFile.FileName)
saveFile = txtPath.Value & filename.Value
While System.IO.File.Exists(saveFile)
filename.Value = myRandom() & System.IO.Path.GetExtension(htpFile.FileName)
saveFile = txtPath.Value & filename.Value
End While
htpFile.SaveAs(saveFile)
imgFile.ImageUrl = "tmp\" & filename.Value
'imgFile.ImageUrl = ResolveUrl(saveFile)
' errMsg.Text = "<b><font color=red>" & "Upload Success ! please Save" & "</font></b>"
Return True
Catch exp As Exception
errMsg.Text = exp.ToString()
Return False
End Try
End Function
'=================================================
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货