Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my machine I have installed Windows 7 along with IIS 7.5.
I have created virtual path as "TestAsp" ("C:\inetpub\wwwroot\TestAsp").
I am unable to download a file which more than 2 KB

I have used following code in a asp file to download a file
ASP
<%
'Set the content type to the specific type that you are sending.

strFilePath = "C:\inetpub\wwwroot\TestAsp\Bin\Test1big.txt"
'Note : File size of 'Test1Big.txt' is morethan 2 KB

Set fso = CreateObject("Scripting.FileSystemObject")
if fso.FileExists(strFilePath) Then
	set file = fso.GetFile(strFilePath)	
		
	Response.buffer = TRUE  
	Response.Expires = 0
	Response.Clear
	Response.ContentType = "application/octet-stream"
	Response.AddHeader "Document", fso.GetFileName(strFilePath)
	Response.AddHeader "Content-Length", file.size	
	Response.AddHeader "Content-Disposition", "attachment; FileName=" &
		fso.GetFileName(strFilePath)
	Const adTypeBinary = 1
	Set objStream = Server.CreateObject("ADODB.Stream")
	objStream.Open
	objStream.Type = adTypeBinary
	objStream.LoadFromFile strFilePath
	Response.BinaryWrite objStream.Read
	objStream.Close
	Set objStream = Nothing
Else
	Response.Write("File " & strFilePath & " does not exist.")
End if
Set fso = Nothing
%>

During my further investigation I have found that the following line in the asp page was causing the problem
"Response.AddHeader "Content-Length", file.size"
Once I comment the above line from the asp page I was able to download a file which is more than 2 KB.

I want to download a file without commneting above said line.

Can you help me on this

Thx in advance

Zulfiqar
Posted
Updated 24-Feb-10 17:12pm
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900