pass conventional html upload form to asp.net page for processing

J

Jon Paal

how can I pass conventional html upload form to asp.net page for processing /

like : (which currently does not work)



<form name="userForm" action="upload.aspx" ENCTYPE="multipart/form-data" method="post" >
<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" />
 

Ask a Question

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.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top