Internet Products
1821994 Members
3422 Online
109638 Solutions
New Discussion юеВ

Forcing IE5 to download a non-registered file type

 
steve_20
New Member

Forcing IE5 to download a non-registered file type

It appears that IE5.5 is far too clever for its own good where file downloads are concerned,well, for our apps at least.

We use file extensions like ".pou" & ".uin"
These files are created in ASP on IIS4 and
a link allowed users to download file locally to put on a floppy disc.

This worked since IE4 didn't recognise file ext
so "file download dialogue" was automatically invoked.

Unfortunately for us IE5.5 "data-sniffs" the file,determines it to be text and simply opens file directly in browser.

Does any one know of any clean fix to this?
It seems registry entries not applicable and we cannot add any mime-type stuff internally since the file is sent off to be read by a program (fixed length fields etc.)

Thanks
Steve

4 REPLIES 4
Jamie Hughes
Honored Contributor

Re: Forcing IE5 to download a non-registered file type

Hello Steve,

You're right, IE is a bit too secure for its own good sometimes. You might be able to use IFRAME linking or Internet Code Download Linking. Here is an excellent Microsoft article that explains both of these workarounds.

http://support.microsoft.com/support/kb/articles/Q232/0/77.ASP

I'm not sure if either of those would work in your environment but I can't think of any other ways to do this right now. I hope that helps.

Best regards,
Jamie Hughes

Tim Malnati
Honored Contributor

Re: Forcing IE5 to download a non-registered file type

As a work-around to this you could RIGHT click on the object and select 'Save Target As' from the popup menu. This option will also allow you to select the target location of the saved file.
steve_20
New Member

Re: Forcing IE5 to download a non-registered file type

Spent a day trolling the web for this so for anyone with similar problem as mine here is solution...

Need to set HTTP Headers on IIS5 for your particular file extension:

Go to :Internet Information Services//

Right click to display Properties, click HTTP Headers.

in Mime Map section click Filetypes/New Type

Add (in my case) "pou" with Content-Type(Mime Type) of "application/unknown"

"Application/unknown" is the key to invoking the file download dialogue, it basically tells IE5 not to be clever and do as its told!!!

Note:
No client-side configs are relevant to this
working but you do need to have control/access to the web-server

Thanks for quick replies

Steve







rani sajja
New Member

Re: Forcing IE5 to download a non-registered file type

Hi,

I'm trying to force a file download using asp.I have seen lots for code samples to achieve this.

I'm able to pop up the Open save dialog box when the user clicks a button.The file that i'm trying to force
download is a video file with .asf as the extension.When yo hit on Save,it lets you download the file and you can play it from there.
The only problem is with the Open.If you hit open on the force file dialog box,it tries to open the file inside windows media player
but fails to do.

Does anyone know why it is doing this?I have tried the same code with other files(excel,word) and they all work fine.Open opens them and save lets to save it locally.
Why not with .asf..no clue.

I tried what you said..it does not seem to work...


Here is my code

One way-------

<%

Response.Buffer = True
Dim strFilePath, strFileName

Const adTypeBinary = 1

strfilepath = "C:\inetpub\wwwroot\data\54325\ranitest1.asf"
strFileName = "ranitest1.asf"

Response.Clear

Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath

strFileType = lcase(Right(strFileName, 4))

' Feel Free to Add Your Own Content-Types Here
Select Case strFileType
Case ".asf"
ContentType = "video/x-ms-asf"
Case ".avi"
ContentType = "video/avi"
Case ".doc"
ContentType = "application/msword"
Case ".zip"
ContentType = "application/zip"
Case ".xls"
ContentType = "application/vnd.ms-excel"
Case ".gif"
ContentType = "image/gif"
Case ".jpg", "jpeg"
ContentType = "image/jpeg"
Case ".wav"
ContentType = "audio/wav"
Case ".mp3"
ContentType = "audio/mpeg3"
Case ".mpg", "mpeg"
ContentType = "video/mpeg"
Case ".rtf"
ContentType = "application/rtf"
Case ".htm", "html"
ContentType = "text/html"
Case ".asp"
ContentType = "text/asp"
Case Else
'Handle All Other Files
ContentType = "application/octet-stream"
End Select


Response.AddHeader "Content-Disposition", "attachment; filename=" & strFileName
Response.AddHeader "Content-Length", strFileSize

Response.Charset = "UTF-8"
Response.ContentType = ContentType

Response.BinaryWrite objStream.Read
Response.Flush

objStream.Close
Set objStream = Nothing

%>

Other way-------

<%

Function getBinaryFile(strFilePath)

Dim TypeBinary, oStream


TypeBinary = 1


Set oStream = Server.CreateObject("ADODB.Stream")


oStream.Open


oStream.Type = TypeBinary

oStream.LoadFromFile strFilePath



getBinaryFile = oStream.read

Set oStream = Nothing

End Function

sServerFile = Server.MapPath("/data/54325/test.asf")
'sFile = "CTC012.pdf"
sfile = "ranitest11.asf"
Response.Buffer = True
Response.Clear

'Response.Flush
' I want the file displayed within the browser so dont specify a filename


Response.AddHeader "content-disposition", "attachment; filename=" & sFile
Response.ContentType = "video/x-ms-asf"
Response.BinaryWrite getBinaryFile(Server.MapPath("/data/54325/test.asf"))
response.flush
Response.end
%>

other way---
<%
Dim Stream
Dim Contents
Dim FileName
dim filename1
FileName1 = "ranitest2.asf"
filename = "\data\54325\ranitest2.asf"
Response.ContentType = "application/force-download"
Response.AddHeader "content-disposition", "attachment; filename=" & FileName1
Set Stream = server.CreateObject("ADODB.Stream")
Stream.Open
Stream.LoadFromFile Server.MapPath(FileName)
Contents = Stream.ReadText
Response.BinaryWrite Contents
Stream.Close
Set Stream = Nothing

%>

otherway---
<%
FileName = "test122.asf"

Set Stream = Server.CreateObject("ADODB.Stream")
Stream.Open
Stream.LoadFromFile Server.MapPath("data/54325/test122.asf")
Response.ContentType = "video/x-ms-asf"
Response.AddHeader "content-disposition", "attachment; filename =" & filename

Contents = Stream.ReadText
Response.BinaryWrite Contents
Stream.Close
Set Stream = Nothing
%>

other way----

<%

File= "phonelist1.xls"

filename = "c:\inetpub\wwwroot\data\54325\phonelist1.xls"

Response.Buffer=True

Set FSO = Server.CreateObject("Scripting.FileSystemObject")

Set File = FSO.GetFile(Server.MapPath("data\54325\" & File))
response.write filename
'response.end

Set TS=FSO.OpenTextFile(File)

Response.contenttype="application/vnd.ms-excel"

Response.AddHeader "Content-Disposition", "attachment; filename=" & file

Response.BinaryWrite TS.readall & ""

TS.close

Set TS = Nothing

set File = Nothing

Set FSO = Nothing

%>