Link to home
Start Free TrialLog in
Avatar of meat_dog
meat_dog

asked on

Automatic Download

I am using the following case to automatically download when a user clicks on a link.  The code works good for all files being downloaded that are smaller than about 4M.  Any 4M file and larger seems to generate a page cannont be displayed error.  Possibly some type of memory error/allocation I'm not sure...  How can I fix this, or is there an entirely different way to be going about solving my problem.  

      case "download"
                  dim filedir
                  filedir = request.querystring("dir")
                  
                  Response.Buffer = True
                  strFileName= "00000001.tif"
                  strFilePath=server.mappath(filedir&"\"&strFileName)
'                  strFilePath= "C:\Onetrac\Programs\intranet site\Oldstone\" & filedir &"\"
                  response.write(strFilePath)
                  set fso=createobject("scripting.filesystemobject")
                  set f=fso.getfile(strFilePath)
                  strFileSize = f.size
                  set f=nothing: set fso=nothing
                  Const adTypeBinary = 1
                  Response.Clear
                  Set objStream = Server.CreateObject("ADODB.Stream")
                  objStream.Open
                  objStream.Type = adTypeBinary
                  objStream.LoadFromFile strFilePath
                  strFileType = "image/tif" ' change to the correct content type for your file
                  Response.AddHeader "Content-Disposition", "attachment; filename=" & filedir & ".tif"
                  Response.AddHeader "Content-Length", strFileSize
                  Response.Charset = "UTF-8"
                  Response.ContentType = strFileType
                  Response.BinaryWrite objStream.Read
                  Response.Flush
                  objStream.Close
                  Set objStream = Nothing

Avatar of amit_g
amit_g
Flag of United States of America image

Are you on IIS6 or using ASP.NET?
Avatar of meat_dog
meat_dog

ASKER

I am using IIS6 and ASP.NET is installed on the server.  However I have never used the ASP.NET framwork.
After reviewing the articles I have concluded that i do not have URLSCAN installed.  The .exe for the program and required dll's are not on the system.
simply change the default transfer limit in web.config file. (the default is 4 mb for security)

<?xml version="1.0" encoding="UTF-8" ?>
 <configuration>
   <configSections>
    <system.web>
     <httpRuntime
      executionTimeout="90"
      maxRequestLength="10240" <!-- 10Mb -->
      useFullyQualifiedRedirectUrl="false"
     />
    </system.web>
   </configSections>
 </configuration>
I have never used a web.config file before.  How do i include the web.config file in my asp page?  Does anyting else other than your above code, need to be in the web.config file?  Do i need to do anything in the .Net config tool, or IIS Manager?  thank you..
still having a problem
ASKER CERTIFIED SOLUTION
Avatar of amit_g
amit_g
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I decided to give the above the points for pointing me in the correct direction.  I was not used to using metadata.xml, but found that it was setting up values such as response.buffer and response.buffer.size ( AspBufferingLimit) before even loading the page... Anyway, thank you for pointing me in the correct direction.
How did you fix it? Did you increase the buffer size limit or turned off the buffering in the page?

Please read the following links. It is important to grade fairly or else most people will be reluctant to help you in future. Please note that they can see your grading record in your profile and most do before answering.

https://www.experts-exchange.com/help/closing.jsp#7
https://www.experts-exchange.com/help/#12
A request has been made to change the grade. The expert feels the current grade does not fit the criteria of the intended guidelines.  Those guidelines can been seen at

https://www.experts-exchange.com/help/Closing.htm#7

If there is no response in 72 hours, I will review this question and grade accordingly.

YensidMod
Community Support Moderator @Experts Exchange
YensidMod
      Please change the grade to an A.  amit_g sorry if i gave you a bad grade, i did not understand the ramifacations before.  I do now and it won't happen again.

   YensidMod,
          just so you know the link you gave me is incorrect, however amit_g provided me with the correct link.  thank you amit_g
Grade change to an A.

Yensidmod
EE Moderator
Thanks meat_dog and YensidMod :)
I am having the same problem as meat dog, only I am trying to download PDFs instead of TIF files.  My code worked fine on IIS 4.0 and IIS 5.  Any suggestions.  I have turned off buffering in the page, and it still fails.
jimster909 - the problem was found on the actual webserver it's self.. not the webpages you are creating... in addition to turning buffering off (not really sure that even helped) look on the server for the "metadata.xml" file.  It contains a varialbe that limits the downloads to 4m...  Not sure exactly the name of the variable but i think it is  AspBufferingLimit...  If not ( AspBufferingLimit) then check response.buffer and response.buffer.size... good luck...