form question

  • Thread starter Thread starter Jon Paal
  • Start date Start date
J

Jon Paal

is it possible to submit a conventional html upload form to an ASPx file for processing ?
 
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.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer

A watched clock never boils.
 
so why is this not working ?


===== default.htm ===========

<form name="userForm" action="upload.aspx" ENCTYPE="multipart/form-data" method="post" runat="server" >
<input id="uploadedFile" type="file" >
<input type="submit" id="upload" value="Upload" >
</form>

===== 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>

<asp:label id="Label1" runat="server" />
 
Back
Top