Since we can only have 1 form per aspx file, is it possible to include a file upload process on the same form as other webcontrols? Thanks regards,
Brian
Brian. Not sure if this will help, but I would think that if you have a Subroutine (as below) in your codebehind it should be enough, and shouldn't be in anyway incompatible with the rest of your code. Just a few lines of code (uploads an image and sticks it into an Access table):
Sub DoUpload(Sender As Object, e As System.EventArgs)
Dim sPath as String
Dim sFile as String
Dim sFullPath as String
Dim sSplit() as String
Dim sPathFriendly as String
'Upload to same path as script
'Internet Anonymous User must have write permissions
sPath = Server.MapPath(".\Photos"
If Right(sPath, 1) <> "\" then
sPathFriendly = sPath 'Friendly path name for display
sPath = sPath & "\"
Else
sPathFriendly = Left(sPath, Len(sPath) - 1)
End If
'Save as same file name being posted
'The code below resolves the file name
'(removes path info)
sFile = txtUpload.PostedFile.FileName
sSplit = Split(sFile, "\"
sFile = sSplit(Ubound(sSplit))
sFullPath = sPath & sFile
Try
txtUpload.PostedFile.SaveAs(sFullPath)
Catch Ex as Exception
lblResults.Text = "Upload of File " & sFile & " to " & sPathFriendly & " failed for the following reason: " & Ex.Message
Finally
'...
End Try
'and now stick the image in the dbase table...
'here I am sticking a comment field and an image...
Dim strString As String
strString = txtMemo.Text
strString = strSTring.Replace("'","''" 'replace apos
Dim dbconn As OleDbConnection
Dim DBCommand As OleDBDataAdapter
Dim DBInsert As New OleDbCommand
'Open the database connection
dbconn = New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Data Source=" & Server.MapPath (".\fpdb\NewRecords.mdb;")
DBInsert.CommandText = "INSERT INTO tblPhotos (Comments, AwwSiteCode) VALUES ('" & strString & "', '" & Me.lblID.Text & "')"
DBInsert.Connection = dbconn
DBInsert.Connection.Open
DBInsert.ExecuteNonQuery()
DBInsert.Connection.Close
Response.Redirect(".\PHotoConfirm.aspx?AwwSiteCode=" & MyID)
End Sub
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.