Solved

prevent browser to open text and pdf files..

Posted on 2006-07-24
4
353 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:neeraj523
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 17166044
Hi neeraj523,

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

http://www.experts-exchange.com/Web/Web_Languages/ASP/Q_20811501.html

Apresto
0
 
LVL 6

Accepted Solution

by:
darkeryu earned 500 total points
ID: 17166603
HI:

using asp you can:

<%
  snfile="/foldername/filename"
  set fs=server.CreateObject("scripting.filesystemobject")
  if fs.FileExists(server.MapPath(snfile))=true then
    set objfile=fs.GetFile(server.MapPath(snfile))
    size=objfile.size
    fname=objfile.name
    mime_type="application/save-as"
    Response.AddHeader "Expires:",0
    Response.ContentType=mime_type
    Response.AddHeader "Content-Disposition","attachment; filename="&fname
    set objStream =server.CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type=1
    objStream.LoadFromFile server.MapPath(snfile)
    Response.BinaryWrite objStream.Read
  else
    Response.Write "File not found!"
    Response.End
  end if
 
%>
0
 
LVL 22

Author Comment

by:neeraj523
ID: 17166633
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
0
 
LVL 10

Expert Comment

by:eguilherme
ID: 17191954
<%
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()
%>
0

Featured Post

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question