Solved

Cannot call BinaryRead after using Request.Form collection.

Posted on 2010-11-22
11
1,676 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
  • 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
 
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 500 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now