what is the problem?

Results 1 to 2 of 2

Thread: what is the problem?

  1. #1
    Join Date
    Dec 1969

    Default what is the problem?

    I am working on trying to force a download from a webbrowser on different types of files like zip,tar,doc,xls,txt,html etc. <BR><BR>I am testing on IE 5.01 and netscape 4.77. <BR><BR>The problem is that, it doesn&#039;t work properly <BR><BR>1) for doc, xls , txt files the files shown directly in the browser instead of download. <BR>or <BR>instead of downloading the those file, the asp file itself is getting downloaded. <BR>2)i am unable make code compatible for both the browsers.. <BR><BR>The code is <BR><BR>function getContentType(sFileType) <BR><BR> if instr(lcase(sFileType),"zip") &#060;&#062; 0 then <BR> getContentType="application/x-gzip" <BR> elseif instr(lcase(sFiletype),"html") &#060;&#062; 0 then <BR> getContentType="text/html" <BR> .......... <BR><BR> end if <BR><BR>end function <BR><BR>dim size,stype <BR>set oFS = server.CreateObject("Scripting.FileSystemobject") <BR>set oFile = oFS.GetFile(request("file_name")) <BR>size = ofile.Size <BR>sType = oFile.type <BR>set ofile = nothing <BR>set oFS = nothing <BR><BR><BR>&#039;Add Headers and download the file <BR>dim sHeader <BR>Dim vntStream,oMyObject <BR><BR>Response.Buffer = TRUE <BR>sHeader= "inline; filename=" & request("file_name") <BR><BR>Response.AddHeader "content-disposition",sHeader <BR>Response.AddHeader "content-length",size <BR>Response.ContentType = GetContentType(sType) <BR>Response.CacheControl = "public" <BR><BR>Set oMyObject = Server.CreateObject("MyObject.BinRead") <BR>vntStream = oMyObject.readBinFile(request("file_name")) <BR>Response.BinaryWrite(vntStream) <BR><BR><BR>Myobject.binread is a activex dll <BR>**************** <BR> Function readBinFile(ByVal bfilename As String) As Variant <BR> Dim fl As Long <BR> Dim FileNum As Long <BR> Dim binbyte() As Byte <BR> Dim binfilestr As String <BR><BR> On Error GoTo errHandler <BR> <BR> FileNum = FreeFile <BR> Open bfilename For Binary Access Read As #FileNum <BR><BR> fl = FileLen(bfilename) <BR> ReDim binbyte(fl) <BR><BR> Get #FileNum, , binbyte <BR><BR> Close #FileNum <BR><BR> readBinFile = binbyte <BR> Exit Function <BR><BR>errHandler: <BR> Exit Function <BR> End Function <BR><BR><BR>Can anyone tell me where exactly is the problem ? <BR><BR>--------------------------------------------------------------------------------<BR>

  2. #2
    Join Date
    Dec 1969

    Default Force File Download

    Perhaps check out the following:<BR><BR>Force "file download" for known file types<BR>http://www.kosob.com/detail.asp?t=t&id=516<BR>"Suppose you have written an ASP page that contains a link to a known MIME type, but you want the user to download the file instead of viewing it. Add the following to your script:<BR> response.addHeader "content-disposition", "attachment;filename=filename.ext"<BR>Then substitute the actual filename and extension, and it is as good as done. When your users click on the link, they will immediately see the download dialog box instead of the files contents.<BR><BR>Another solution would be to zip the file that you want to be downloaded.<BR><BR>Best regards,<BR>-Paul<BR><BR>Bullschmidt.com - Databases on the Web<BR>http://www.Bullschmidt.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts