?
Solved

prevent browser to open text and pdf files..

Posted on 2006-07-24
4
Medium Priority
?
354 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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

777 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