Aleks
asked on
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=(Casesjo in.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=(Casesjo in.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_Pa ge)
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("Attachm entsfull") %>/<%=(Rec eipts.Fiel ds.Item("s torage_nam e").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.
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=(Casesjo
----
'Force Download Server Behavior
On Error Resume Next
If Request("Attachments")<>""
Response.Buffer=true
File_Path = Request("Attachments")
Error_Page = "error.asp?caseid=(Casesjo
Set FS = Server.CreateObject("ADODB
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
Response.BinaryWrite FS.Read
FS.Close
Response.End
Else
Response.Redirect(Error_Pa
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("Attachm
<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.
ASKER
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.
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.
ASKER
Thanks for the syntax ... that part works fine now!
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?
what if you hard code a value for the path, does that work?
ASKER
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_0 5262015202 949_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.
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\
<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.
ASKER
I submitted the form to another page and requested the form value of "Attachments" and shows up empty :$
ok do you have any other fields on the page with a name of "Attachments"?
is the Attachments field contained in a form?
is the Attachments field contained in a form?
ASKER
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\BlueDot Dev/2_1078 9_05262015 202949_Bir th Certificate.pdf, C:\BDotAttachments\BlueDot Dev/2_1078 9_05262015 202949_Bir th Certificate.pdf, C:\BDotAttachments\BlueDot Dev/2_1078 9_05262015 202949_Bir th Certificate.pdf, C:\BDotAttachments\BlueDot Dev/2_1078 9_05262015 202949_Bir th Certificate.pdf
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\BlueDot
ASKER
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\BlueDot Dev/2_1078 9_05262015 204507_Wel come letter.txt, C:\BDotAttachments\BlueDot Dev/2_1078 9_05262015 202949_Bir th Certificate.pdf, C:\BDotAttachments\BlueDot Dev/2_1078 9_05262015 202913_Per sonal Document.DOCX, C:\BDotAttachments\BlueDot Dev/2_1078 9_05262015 202424_Wel come letter.txt
C:\BDotAttachments\BlueDot
ASKER
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.
so you have multiple fields called "Attachments" on your page? and your goal is to have them all downloaded?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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)
(Had I never hard coded it I would have not noticed)
ASKER
It worked :) thanks for the help.
ASKER
Thanks !
Error_Page = "error.asp?caseid=" & Casesjoin.Fields.Item("Id"
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?