473,386 Members | 1,803 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Downloading with ASP

347 100+
I am using the following code to make a button that downloads files from my server, the problem is that once the file size gets over 3mb it wont download and just hangs, is this a problem with the code???

Expand|Select|Wrap|Line Numbers
  1. <%@Language="VBScript"%>
  2. <%Option Explicit%>
  3. <%Response.Buffer = True%>
  4. <%
  5. On Error Resume Next
  6. Dim strPath
  7. strPath = CStr(Request.QueryString("file"))
  8. '-- do some basic error checking for the QueryString
  9. If strPath = "" Then
  10.     Response.Clear
  11.     Response.Write("No file specified.")
  12.     Response.End
  13. ElseIf InStr(strPath, "..") > 0 Then
  14.     Response.Clear
  15.     Response.Write("Illegal folder location.")
  16.     Response.End
  17. ElseIf Len(strPath) > 1024 Then
  18.     Response.Clear
  19.     Response.Write("Folder path too long.")
  20.     Response.End
  21. Else
  22.     Call DownloadFile(strPath)
  23. End If
  24.  
  25. Private Sub DownloadFile(file)
  26.     '--declare variables
  27.     Dim strAbsFile
  28.     Dim strFileExtension
  29.     Dim objFSO
  30.     Dim objFile
  31.     Dim objStream
  32.     '-- set absolute file location
  33.     strAbsFile = Server.MapPath(file)
  34.     '-- create FSO object to check if file exists and get properties
  35.     Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  36.     '-- check to see if the file exists
  37.     If objFSO.FileExists(strAbsFile) Then
  38.         Set objFile = objFSO.GetFile(strAbsFile)
  39.         '-- first clear the response, and then set the appropriate headers
  40.         Response.Clear
  41.         '-- the filename you give it will be the one that is shown
  42.         ' to the users by default when they save
  43.         Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name
  44.         Response.AddHeader "Content-Length", objFile.Size
  45.         Response.ContentType = "application/octet-stream"
  46.         Set objStream = Server.CreateObject("ADODB.Stream")
  47.         objStream.Open
  48.         '-- set as binary
  49.         objStream.Type = 1
  50.         Response.CharSet = "UTF-8"
  51.         '-- load into the stream the file
  52.         objStream.LoadFromFile(strAbsFile)
  53.         '-- send the stream in the response
  54.         Response.BinaryWrite(objStream.Read)
  55.         objStream.Close
  56.         Set objStream = Nothing
  57.         Set objFile = Nothing
  58.     Else 'objFSO.FileExists(strAbsFile)
  59.         Response.Clear
  60.         Response.Write("No such file exists.")
  61.     End If
  62.     Set objFSO = Nothing
  63. End Sub
  64. %>
Jun 18 '09 #1
0 1496

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Luke StClair | last post by:
Only marginally belonging in this newsgroup... but oh well. I've just started writing in python, and I want to make the files available on the web. So I did the standard <a...
2
by: Dave | last post by:
Dear Sirs, Is there a way to get the width and height of an image without downloading the image, or with just downloading a minimal portion of the image? For instance, I have a list of 10,000...
0
by: TJ | last post by:
Hi, I've written code web-based uploading and downloading. Here is some code for it. For saving file into MS-SQL database, SaveFileIntoDB(HttpPostedFile file) { int fileLength =...
2
by: Bala | last post by:
Hi I am trying to download the PDF files from my webserver using ASP.Net. All my files are stored at F Drive on webserver. Like this F:\Main Folder\Sub Folder\Files\File1.pdf I am...
4
by: Joe | last post by:
I'm hosting my web service on a Windows 2003 box which is remotely located. When trying to add a web reference to a C# project I get an error message 'There was an error downloading...
1
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
3
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
5
by: fniles | last post by:
We created an ActiveX control and marked it as safe for scripting using Implements IObjectSafety. We then created a CAB file and signed it using Verisign. We also created a license file (LPK file)...
0
by: just.starting | last post by:
I am having problem while downloading files from an apache server2.0.53 with php4.3.10.While downloading some files it generally stops after downloading some specific amount and then stops...
23
by: Doug van Vianen | last post by:
Hi, Is there some way in JavaScript to stop the downloading of pictures from a web page? Thank you. Doug van Vianen
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.