• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2391
  • Last Modified:

Cannot call BinaryRead after using Request.Form collection.

I know there are various posts about this issue on here, but i cant seem to get my head around any of them.

I am trying to upload a file and do some database insertions and email sending as well. So the users submits the form and it goes to this 'processing' page.
The first bit contains
if Request.Form("file1") > "" then
' Create the FileUploader
Dim Uploader, File
Set Uploader = New FileUploader

' This starts the upload process
Uploader.Upload()

'******************************************
' Use [FileUploader object].Form to access 
' additional form variables submitted with
' the file upload(s). (used below)
'******************************************

	' Loop through the uploaded files
	File = Request.Fields("file1").value
		
			File.SaveToDisk "C:\inetpub\wwwroot\helpdesk\uploads\"


end if

Dim CategoryID
Dim Subject
Dim Description
Dim AFRNumber
Dim Priority
Dim UserID
Dim Telephone
Dim Location
Dim Email
Dim CurrentDateTime

CategoryID = Request.Form("CATEGORY")
 Subject = Request.Form("SUBJECT")
 Description = Request.Form("DESC")
 AFRNumber = Request.Form("AFR")
 Priority = Request.Form("PRIORITY")
 UserID = Request.Form("USERID")
 Telephone = Request.Form("TELEPHONE")
 Location = Request.Form("LOCATION")
 Watch = Request.Form("WATCH")
CurrentDateTime = Now()

	Set CurrentUser = Server.CreateObject ("ADODB.Command")
	CurrentUser.ActiveConnection = HELPDESK_CONN

Open in new window

and continues on to insert data into a SQL database and send an email.

However i cant seem to get past this with the Upload bit at the beginning, without the error

Request object error 'ASP 0206 : 80004005'

Cannot call BinaryRead

/Helpdesk/upload_script/uploadinclude.asp, line 46

Cannot call BinaryRead after using Request.Form collection.

What do i do?
0
AVONFRS
Asked:
AVONFRS
  • 7
  • 4
1 Solution
 
saoirse1916Commented:
The problem is that you can't use Request.Form once you've instantiated an Upload class -- I'm assuming you're using the ASP Upload Without COM or something similar.  If it's that one, you'll need to change this:

CategoryID = Request.Form("CATEGORY")
 Subject = Request.Form("SUBJECT")
 Description = Request.Form("DESC")
 AFRNumber = Request.Form("AFR")
 Priority = Request.Form("PRIORITY")
 UserID = Request.Form("USERID")
 Telephone = Request.Form("TELEPHONE")
 Location = Request.Form("LOCATION")
 Watch = Request.Form("WATCH")

Open in new window


Into this:

CategoryID = Upload.Fields("CATEGORY").Value
 Subject = Upload.Fields("SUBJECT").Value
 Description = Upload.Fields("DESC").Value
 AFRNumber = Upload.Fields("AFR").Value
 Priority = Upload.Fields("PRIORITY").Value
 UserID = Upload.Fields("USERID").Value
 Telephone = Upload.Fields("TELEPHONE").Value
 Location = Upload.Fields("LOCATION").Value
 Watch = Upload.Fields("WATCH").Value

Open in new window


If you're not using clsUpload, whatever you are using will have something similar though likely with different syntax.
0
 
AVONFRSAuthor Commented:
OK thanks for you reply. I think im sort of getting there.

Ive replaced it with

Dim Uploader, File
Set Uploader = New FileUploader

' This starts the upload process
Uploader.Upload()

'******************************************
' Use [FileUploader object].Form to access 
' additional form variables submitted with
' the file upload(s). (used below)
'******************************************

	' Loop through the uploaded files
	File = Uploader("file1").value
		
			File.SaveToDisk "C:\inetpub\wwwroot\helpdesk\uploads\"

Dim CategoryID
Dim Subject
Dim Description
Dim AFRNumber
Dim Priority
Dim UserID
Dim Telephone
Dim Location
Dim Watch
Dim Email
Dim CurrentDateTime

CategoryID = Uploader.Form("CATEGORY")
 Subject = Uploader.Form("SUBJECT")
 Description = Uploader.Form("DESC")
 AFRNumber = Uploader.Form("AFR")

Open in new window


But now the variables arent filling up with anything. I dont think it knows where to find the Uploader.Form. They are all just blank.
0
 
saoirse1916Commented:
Well, the first thing is to check the form page and make sure those names ("CATEGORY", "SUBJECT", etc.) are all correct and are properly populated there.  Assuming that's the case, replace the first 5 lines of your code with this:

Dim Uploader, File
Set Uploader = New FileUploader

' This starts the upload process
Uploader.Upload()

Response.Write(Uploader.Form("CATEGORY") & "<br>")
Response.Write(Uploader.Form("SUBJECT") & "<br>")
Response.Write(Uploader.Form("DESC") & "<br>")
Response.Write(Uploader.Form("AFR") & "<br>")

Set Uploader = Nothing
Response.End()

Open in new window


That should tell you if you're getting anything passed through those form fields.  If so, then it might be an order problem -- some of those uploading components need to do the processing before any disk operations (File.SaveToDisk, in your case).  If not, then you might have a syntax problem with Uploader.Form -- double-check that to make sure you're calling the form fields properly.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
AVONFRSAuthor Commented:
Those fields are correct as it worked perfectly before i added the file upload section to the form.

I have tried the Response.Write method to see if theyre being filled, thats how i found out they were empty.
0
 
saoirse1916Commented:
Then I'm back to syntax problem with Uploader.Form or an order problem -- did you do your Response.Write before calling the File.SaveToDisk method?  Unfortunately, as I'm not sure what upload component you're working with I can't verify if the Uploader.Form syntax is correct or not or if the component itself even works properly.

I use this: http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=8525&lngWId=4 on a lot of sites and it works great and should work fine with the code that I posted initially.
0
 
AVONFRSAuthor Commented:
OK. I will try the link that you suggested and see how i get on with that.
0
 
AVONFRSAuthor Commented:
I realised when looking through the link you sent me what i had done wrong. In the form that i fill out, i forgot to specify the encType as multipart/form-data.

Thank you for your help.
0
 
AVONFRSAuthor Commented:
Do you have any idea why it might possibly not upload anything bigger than 3KB?

When i go bigger than that i get this error


Microsoft VBScript runtime error '800a0005'

Invalid procedure call or argument

/Helpdesk/upload_script/uploadinclude.asp, line 137

That line is
	Public Sub SaveToDisk(sPath)
		Dim oFS, oFile
		Dim nIndex
	
		If sPath = "" Or FileName = "" Then Exit Sub
		If Mid(sPath, Len(sPath)) <> "\" Then sPath = sPath & "\"
	
		Set oFS = Server.CreateObject("Scripting.FileSystemObject")
		If Not oFS.FolderExists(sPath) Then Exit Sub
		
		Set oFile = oFS.CreateTextFile(sPath & FileName, True)
		
		For nIndex = 1 to LenB(FileData)
		    oFile.Write Chr(AscB(MidB(FileData,nIndex,1)))
		Next

		oFile.Close
	End Sub

Open in new window

0
 
saoirse1916Commented:
Wow -- 3KB is small.  Any script-based solution will have some file size limits but that's a bit extreme.  As I still don't know what upload component you're using then I can only assume that there's a problem with it.
0
 
AVONFRSAuthor Commented:
How do i tell what component i am using?
0
 
AVONFRSAuthor Commented:
I ended up replacing all of the code with the clsUpload component that you recommended to me. It works very well thank you
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now