Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Cannot call BinaryRead after using Request.Form collection.

Posted on 2010-11-22
11
Medium Priority
?
2,078 Views
Last Modified: 2012-05-10
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
Comment
Question by:AVONFRS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
11 Comments
 
LVL 8

Expert Comment

by:saoirse1916
ID: 34191504
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
 
LVL 1

Author Comment

by:AVONFRS
ID: 34194586
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
 
LVL 8

Expert Comment

by:saoirse1916
ID: 34196699
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:AVONFRS
ID: 34197070
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
 
LVL 8

Accepted Solution

by:
saoirse1916 earned 2000 total points
ID: 34197267
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
 
LVL 1

Author Comment

by:AVONFRS
ID: 34197294
OK. I will try the link that you suggested and see how i get on with that.
0
 
LVL 1

Author Comment

by:AVONFRS
ID: 34197346
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
 
LVL 1

Author Comment

by:AVONFRS
ID: 34197596
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
 
LVL 8

Expert Comment

by:saoirse1916
ID: 34198052
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
 
LVL 1

Author Comment

by:AVONFRS
ID: 34203064
How do i tell what component i am using?
0
 
LVL 1

Author Comment

by:AVONFRS
ID: 34203239
I ended up replacing all of the code with the clsUpload component that you recommended to me. It works very well thank you
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question