Certainly. An ASPX Page class is an HttpHandler, which means that it accepts
Requests, and returns Responses. It doesn't have to post only to itself, and
it doesn't have to be posted to from itself, although that is more typical.
===== upload.aspx ===========
<Script runat="server" >
Private Sub Page_Load()
SaveImages()
End Sub 'Page_Load
Private Function SaveImages() As System.Boolean
Dim _files As System.Web.HttpFileCollection = System.Web.HttpContext.Current.Request.Files
Dim _iFile As Integer
Dim _fileName, _fileExtension As System.String
Dim _message As New System.Text.StringBuilder("Files Uploaded:<br>" )
Try
For _iFile = 0 To _files.Count - 1
Dim _postedFile As System.Web.HttpPostedFile = _files(_iFile)
' file is a jpg or gif
'----------------------
_fileName = System.IO.Path.GetFileName(_postedFile.FileName)
_fileExtension = System.IO.Path.GetExtension(_fileName)
If _fileExtension = ".gif" or _fileExtension = ".jpg" Then
_postedFile.SaveAs((System.Web.HttpContext.Current.Request.MapPath("~/uploads/") & _fileName))
_message.Append((_fileName & "<BR>"))
Else
_message.Append((_fileName & " <font color=""red"">failed!! Only .gif and .jpg images allowed!</font> <BR>"))
End If
Next _iFile
Label1.Text = _message.ToString()
Return True
Catch Ex As System.Exception
Label1.Text = Ex.Message
Return False
End Try
End Function 'SaveImages
</script>
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.