Solved

Cannot call BinaryRead after using Request.Form collection.

Posted on 2010-11-22
11
1,864 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
IIS 7 and executing pages using localhost 16 31
MS SQL + date 6 53
Replace value 2 55
how to read the text file and convert it to csv. 5 44
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…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

732 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