Link to home
Start Free TrialLog in
Avatar of neeraj523
neeraj523Flag for India

asked on

prevent browser to open text and pdf files..

Hello

I want to know if there is a way to force web browsers to open download text and pdf documents intsead of opening it there only..

Basically, i want my web users to download pdf and text files intead opening it in the borwser irrespective of their local browser settings.. Is there a way to force browser in this way programatically ??

Thank You

Neeraj
Avatar of apresto
apresto
Flag of Italy image

Hi neeraj523,

I've seen this question asked many a time and this is the only thread i have seen with a reasonable response:

https://www.experts-exchange.com/questions/20811501/download-not-open-pdf-files.html

Apresto
ASKER CERTIFIED SOLUTION
Avatar of darkeryu
darkeryu

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
Avatar of neeraj523

ASKER

Hello darkeryu

I have tried solution given by u.. but not got working fine.. It is opening the download window but gives error that specific server is not not found..

Neeraj
<%
Function ReadBinaryFile(FileName)
  Const adTypeBinary = 1
  Dim BinaryStream
  Set BinaryStream = CreateObject("ADODB.Stream")
  BinaryStream.Type = adTypeBinary
  BinaryStream.Open
  BinaryStream.LoadFromFile FileName
  ReadBinaryFile = BinaryStream.read
end function


Dim fso, f1, Arq, Nome, Ext
Arq = Server.MapPath("test.txt") 'here u specify the location of the file
Set fso = CreateObject("Scripting.FileSystemObject")
Set f1 = fso.GetFile(Arq)
Nome = fso.GetFileName(Arq)
Ext = fso.GetExtensionName(Arq)
Response.Clear()
Response.ContentType = "application/"&Ext
response.AddHeader "Content-Disposition", "attachment; filename="&Nome&""      
response.BinaryWrite(ReadBinaryFile(Arq))
Response.Flush()
%>