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
            Response.Buffer=true
            File_Path = Request("Attachments")
            Error_Page = "error.asp?caseid=(Casesjoin.Fields.Item("Id").Value)"
            Set FS = Server.CreateObject("ADODB.Stream")
            FS.Type = 1
            FS.Open            
            FS.LoadFromFile(File_Path)
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
            File_Name=File_Path
            Response.Clear
            Response.ContentType = "application/octet-stream"
            Response.AddHeader "Content-Disposition", "attachment; filename=" & File_Name
            Response.AddHeader "Content-Transfer-Encoding","binary"
            Response.BinaryWrite FS.Read
            FS.Close
            Response.End
      Else
            Response.Redirect(Error_Page)
      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">
                      </div>

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.
LVL 1
AleksAsked:
Who is Participating?
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 MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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?
0
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.
0
AleksAuthor Commented:
Thanks for the syntax ... that part works fine now!
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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?
0
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">
                      </div>

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.
0
AleksAuthor Commented:
I submitted the form to another page and requested the form value of "Attachments" and shows up empty  :$
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
ok do you have any other fields on the page with a name of "Attachments"?

is the Attachments field contained in a form?
0
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
0
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
0
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.
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
so you have multiple fields called "Attachments" on your page? and your goal is to have them all downloaded?
0
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
so you need to fix how you're populating that hidden field from your database then...
0

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)
0
AleksAuthor Commented:
It worked  :)  thanks for the help.
0
AleksAuthor Commented:
Thanks !
0
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
ASP

From novice to tech pro — start learning today.

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.