Solved

prevent browser to open text and pdf files..

Posted on 2006-07-24
4
348 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
4 Comments
 
LVL 23

Expert Comment

by:apresto
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
<%
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
C# page opens in new window 3 44
ASP Syntax for IF statement 21 51
Classic ASP + JS 4 67
Group by correlation 4 43
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 information …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now