Error on script to download files

I have the script below which is used to download files from the server when user clicks on a button.

I have checked the path and it is the correct one on every record yet in this particular page the code doesn't work  :$  ... any ideas ?

Also there is a syntax error on the re-direct page, how can I pass the record ID to the next page ?

This part:   "error.asp?caseid=(Casesjoin.Fields.Item("Id").Value)"


'Force Download Server Behavior
On Error Resume Next
If Request("Attachments")<>"" Then
            File_Path = Request("Attachments")
            Error_Page = "error.asp?caseid=(Casesjoin.Fields.Item("Id").Value)"
            Set FS = Server.CreateObject("ADODB.Stream")
            FS.Type = 1
If Err.number = 0 Then
            File_Path = Replace(File_Path, "/", "\")
          if InStr(File_Path, "\") <> 0 Then
                  File_Path = Right(File_Path, Len(File_Path) - InStrRev(File_Path, "\"))
            End If
            Response.ContentType = "application/octet-stream"
            Response.AddHeader "Content-Disposition", "attachment; filename=" & File_Name
            Response.AddHeader "Content-Transfer-Encoding","binary"
            Response.BinaryWrite FS.Read
      End If
            File_Path = Nothing
            Error_Page = Nothing
End If

The form that submits the values has the following code:

 <div align="center">
                        <input name="Attachments" type="hidden" id="Attachments" value="<%=Session("Attachmentsfull")%>/<%=(Receipts.Fields.Item("storage_name").Value)%>">
                        <input name="Download" type="submit" class="bodytext" id="Download" value="view">

I checked the session and is correct and so is the storage_name, also the file IS in the correct folder. It simply doesn't download and sends me to the error page when I click on th ebutton to download the file.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Big MontyWeb Ninja at largeCommented:
first, to fix the syntax error, change your code to:

Error_Page = "error.asp?caseid=" & Casesjoin.Fields.Item("Id").Value

when you say "it doesn't work", can you be more specific? if you comment out or remove the line

On Error Resume Next

does an error occur?
AleksAuthor Commented:
It redirects to the error page, even thought the file is there.

Its weird because I use the exact same code on other pages for other downloads and those work just fine.  I checked the value of the storage_name and the path to the file and they are correct, the file is also there. it simply does not download and redirects to the error page.
AleksAuthor Commented:
Thanks for the syntax ... that part works fine now!
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Big MontyWeb Ninja at largeCommented:
does that still occur with the fix to the Error_Page variable i gave previously?

what if you hard code a value for the path, does that work?
AleksAuthor Commented:
It does occur with the fix of the error, it now does send me to the error page. So .. something is causing the error, hence the redirect.

This is a piece of code someone else did for me, so I am not sure how to hard code it.

But this is an example of the path, perhaps you can help me place it in the code so I can test it.

I hardcoded it like this:

 <div align="center">
                        <input name="Attachments" type="hidden" id="Attachments" value="C:\BDotAttachments\BlueDotDev/2_10789_05262015202949_Birth Certificate.pdf">
                        <input name="Download" type="submit" class="bodytext" id="Download" value="view">

which is the path being used and its correct, if I past that on my browser on a new screen I get the file, but this still redirects me to the error page.
AleksAuthor Commented:
I submitted the form to another page and requested the form value of "Attachments" and shows up empty  :$
Big MontyWeb Ninja at largeCommented:
ok do you have any other fields on the page with a name of "Attachments"?

is the Attachments field contained in a form?
AleksAuthor Commented:
Never mind .. there was a typo .. this is the problem.

When there is more than one document it looks like it passes the value of one item * the number of documents I have, instead of the actual value of the selected row:

This is the value I get:

C:\BDotAttachments\BlueDotDev/2_10789_05262015202949_Birth Certificate.pdf, C:\BDotAttachments\BlueDotDev/2_10789_05262015202949_Birth Certificate.pdf, C:\BDotAttachments\BlueDotDev/2_10789_05262015202949_Birth Certificate.pdf, C:\BDotAttachments\BlueDotDev/2_10789_05262015202949_Birth Certificate.pdf
AleksAuthor Commented:
Actually that was the hard coded. When I set the value back to what it should be its passing ALL values and not the one selected, that's what is causing the issue:

C:\BDotAttachments\BlueDotDev/2_10789_05262015204507_Welcome letter.txt, C:\BDotAttachments\BlueDotDev/2_10789_05262015202949_Birth Certificate.pdf, C:\BDotAttachments\BlueDotDev/2_10789_05262015202913_Personal Document.DOCX, C:\BDotAttachments\BlueDotDev/2_10789_05262015202424_Welcome letter.txt
AleksAuthor Commented:
There are no other form fields with the same name. For some reason when there is more than one entry It passes the values of ALL records and not just the one I am selecting  :$  which obviously prompts the error and hence the redirect.
Big MontyWeb Ninja at largeCommented:
so you have multiple fields called "Attachments" on your page? and your goal is to have them all downloaded?
Big MontyWeb Ninja at largeCommented:
so you need to fix how you're populating that hidden field from your database then...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AleksAuthor Commented:
I think I found the issue. It was the way the 'form' was placed in the repeat region. It showed only one result once I changed it .. let me test and confirm.

(Had I never hard coded it I would have not noticed)
AleksAuthor Commented:
It worked  :)  thanks for the help.
AleksAuthor Commented:
Thanks !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.