Public Class index
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents btnUpload As System.Web.UI.WebControls.Button
Protected WithEvents fileupload1 As System.Web.UI.HtmlControls.HtmlInputFile
Protected WithEvents lbStatus As System.Web.UI.WebControls.Label
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
'Put user code to initialize the page here
End Sub
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btnUpload.Click
UploadImage()
End Sub
Sub UploadImage()
If Not (fileupload1.PostedFile Is Nothing) Then 'Check to make sure
we actually have a file to upload
Dim strLongFilePath As String = fileupload1.PostedFile.FileName
Dim intFileNameLength As Integer = InStr(1, StrReverse(strLongFilePath), "\")
Dim strFileName As String = Mid(strLongFilePath, (Len(strLongFilePath) - intFileNameLength)
+ 2)
Select Case fileupload1.PostedFile.ContentType
Case "image/pjpeg", "image/jpeg" 'Make sure we are getting a valid JPG
image
fileupload1.PostedFile.SaveAs(Server.MapPath("\") & strFileName)
lbStatus.Text = strFileName & " was uploaded successfully to: " &
Server.MapPath("\") & strFileName
Case Else
'Not a valid jpeg image
lbStatus.Text = "Not a valid jpeg image"
End Select
End If
End Sub
End Class
|