 |
| ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

March 8th, 2006, 12:00 AM
|
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Help: Pass the image path to another page
Hi,
I have a page named AddPackage.aspx, which allow travel package to be inserted in sql server database. I created a hyperlink, that will redirect user to UploadImage.aspx if they click on it.
In the UploadPage.aspx, maximum 4 photos are allowed to be uploaded. I save the image files in one of folder in my web project, and want to store the image path in database.
How can I pass the image path to AddPackage.aspx that user accessed earlier, so that the details about the travel package, together with the image path, can be inserted into database, after user click Add Button.
Below are my coding to upload image in ImageUpload.aspx:
Private 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("c:\inetpub\wwwroot\ GoHoliday\Packages\" & strFileName)
Case Else
'Not a valid jpeg image
lblStatus.Text = "Not a valid jpeg image"
End Select
End If
If Not (fileUpload2.PostedFile Is Nothing) Then 'Check to make sure we actually have a file to upload
Dim strLongFilePath As String = fileUpload2.PostedFile.FileName
Dim intFileNameLength As Integer = InStr(1, StrReverse(strLongFilePath), "\")
Dim strFileName As String = Mid(strLongFilePath, (Len(strLongFilePath) - intFileNameLength) + 2)
Select Case fileUpload2.PostedFile.ContentType
Case "image/pjpeg", "image/jpeg" 'Make sure we are getting a valid JPG image
fileUpload2.PostedFile.SaveAs("c:\inetpub\wwwroot\ GoHoliday\Packages\" & strFileName)
Case Else
'Not a valid jpeg image
lblStatus.Text = "Not a valid jpeg image"
End Select
End If
If Not (fileUpload3.PostedFile Is Nothing) Then 'Check to make sure we actually have a file to upload
Dim strLongFilePath As String = fileUpload3.PostedFile.FileName
Dim intFileNameLength As Integer = InStr(1, StrReverse(strLongFilePath), "\")
Dim strFileName As String = Mid(strLongFilePath, (Len(strLongFilePath) - intFileNameLength) + 2)
Select Case fileUpload3.PostedFile.ContentType
Case "image/pjpeg", "image/jpeg" 'Make sure we are getting a valid JPG image
fileUpload3.PostedFile.SaveAs("c:\inetpub\wwwroot\ GoHoliday\Packages\" & strFileName)
Case Else
'Not a valid jpeg image
lblStatus.Text = "Not a valid jpeg image"
End Select
End If
If Not (fileUpload4.PostedFile Is Nothing) Then 'Check to make sure we actually have a file to upload
Dim strLongFilePath As String = fileUpload4.PostedFile.FileName
Dim intFileNameLength As Integer = InStr(1, StrReverse(strLongFilePath), "\")
Dim strFileName As String = Mid(strLongFilePath, (Len(strLongFilePath) - intFileNameLength) + 2)
Select Case fileUpload4.PostedFile.ContentType
Case "image/pjpeg", "image/jpeg" 'Make sure we are getting a valid JPG image
fileUpload4.PostedFile.SaveAs("c:\inetpub\wwwroot\ GoHoliday\Packages\" & strFileName)
Case Else
'Not a valid jpeg image
lblStatus.Text = "Not a valid jpeg image"
End Select
End If
End Sub
Thanks for any help.
Regards,
Ai Ling
|
|

March 8th, 2006, 08:32 PM
|
|
Wrox Technical Editor
|
|
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You could use session variables to pass the image paths between your different .aspx files.
Using Session State: http://samples.gotdotnet.com/quickst...x#sessionstate
- A.Kahtava
|
|

March 9th, 2006, 10:14 PM
|
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi A.Kahtava,
i now use the session to pass the path, and it works.
but now i face another problem, I allow the maximum quantity of photo uploaded to be 4, but the user is allowed to upload 0, 1, 2, 3 or 4 photos.
If photo uploaded is not 4, for example 2, have error message say cannot get the part of the path for image2. Even though i set in databse the image2 can be null.
I now using session to pass the quantity of photo uploaded and the path to another page, then use cases to determine how many photos are going to be displayed.
But I'm quite not sure bout how to proceed with it. Can somebody give me any idea?
Thanks for any help.
Ai Ling
|
|

March 9th, 2006, 11:54 PM
|
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi,
I already solved the problem.
I assign the session to be "-" when no image is uploaded.
Thanks.
ai ling
|
|

March 10th, 2006, 11:34 PM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
If you are going to have many users, using session variables will hit the performance. So I would suggest using a query string to the previous page instead of session variable. Ofcourse, it will give a clue to the user which really don't hurt if correct measures are taken.
Regards,
Puli
|
|

March 11th, 2006, 11:09 PM
|
|
Wrox Technical Editor
|
|
Join Date: Dec 2005
Posts: 271
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Keep in mind that query strings have a maximum length, this length is different for each browser and browser version.
From experience; storing filenames and folder locations can easily exceed the query string limitations.
Session variables may hit performance, but the hardware and processing power of todays computers may not even show a performance hit.
- A.Kahtava
|
|

March 12th, 2006, 09:21 PM
|
|
Authorized User
|
|
Join Date: Apr 2005
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
hi,
may i know what is perforamce hit?
Thanks.
Ai Ling
|
|

March 13th, 2006, 10:19 AM
|
|
Authorized User
|
|
Join Date: Mar 2006
Posts: 31
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ling, to be simple, its nothing but the load on server slowing down the processing speed. Since the session info is a varable stored on server, if too much of information is stored then it might slow down the processing speed. But I agree with Kahtava, the hardware is becoming so good, that we won't feel the slow processing.
Sai Puli
|
|
 |