best way

Results 1 to 3 of 3

Thread: best way

  1. #1
    Join Date
    Dec 1969

    Default best way

    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>vntStre am = oMyObject.readBinFile(request("file_name"))<BR>Res ponse.BinaryWrite(vntStream)<BR><BR><BR>Myobject.b inread 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>

  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><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>Best regards,<BR>-Paul<BR><BR> - Databases on the Web<BR>

  3. #3
    Join Date
    Dec 1969

    Default RE: Force File Download

    Well I&#039;ve tried this and it makes no difference whatsoever.<BR><BR>Tha main problem I had was with Microsoft Office files and MS Project.<BR><BR>I found the answer at<BR><BR><BR>although it isn&#039;t an elegant solution and this can be easily affected by the user changing file type options.<BR><BR><BR>The only file type that I have come across so far that this did not work for was .PPT (PowerPoint) Whatever I do, it opens embedded in the browser, so if anyone has any suggestions to solve that it would be appreciated.<BR><BR>cheers<BR>mf<BR><BR>

Posting Permissions

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