Solved

File type in ADODB.Stream

Posted on 2006-06-22
6
1,286 Views
Last Modified: 2013-12-03
Hi Experts,

To offer visitors a download without giving away the path to the file, I implemented the code as described in Microsofts Knowledge Base article "Use of the ADODB.Stream Object to Send Binary Files to the Browser through ASP" (http://support.microsoft.com/support/kb/articles/q276/4/88.asp).

Most of the files I want to send are PDF, so I changed
            Response.ContentType = "application/octet-stream"
to
            Response.ContentType = "application/pdf"

Is there any way to set the mime type automatically?
0
Comment
Question by:WebJoe
[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
  • 3
  • 3
6 Comments
 
LVL 7

Accepted Solution

by:
Hecatonchires earned 250 total points
ID: 16966700
dim fileExt
fileExt = ucase(right(objFile.name))
select case fileExt
     case "PDF"
        response.contentType= "application/pdf"
     case "TXT"
        response.contentType= "text"
     case "HTM"
        response.contentType = "text/html"
     default
        response.contentType = "application/octet-stream"
end select
0
 

Author Comment

by:WebJoe
ID: 16967668
I was afraid that would be the answer ... nothing more elegant, like a property of some object (other than file, I already checked that)?
0
 

Author Comment

by:WebJoe
ID: 16971079
so to have a (hopefully) correct content type, you'd have to do

<snip>
        sFileExtension = UCase(Right(sFile, (Len(sFile) - InStrRev(sFile, ".", -1, vbTextCompare))))

        '   Set the content type and stream type according to file extension
        Select Case sFileExtension
            Case "3DM", "3DMF", "QD3", "QD3D"
                sContentType = "x-world/x-3dmf"
            Case "A", "ARC", "ARJ", "BIN", "COM", "DUMP", "EXE", "LHA", "LHX", "LZH", "LZX", "O", "PSD", "SAVEME", "ZOO"
                sContentType = "application/octet-stream"
            Case "AAB"
                sContentType = "application/x-authorware-bin"
            Case "AAM"
                sContentType = "application/x-authorware-map"
            Case "AAS"
                sContentType = "application/x-authorware-seg"
            Case "ABC"
                sContentType = "text/vnd.abc"
            Case "ACGI", "HTM", "HTML", "HTMLS", "HTX", "SHTML"
                sContentType = "text/html"
            Case "AFL"
                sContentType = "video/animaflex"
            Case "AI", "EPS", "PS"
                sContentType = "application/postscript"
            Case "AIF", "AIFC", "AIFF"
                sContentType = "audio/aiff"
            Case "AIM"
                sContentType = "application/x-aim"
            Case "AIP"
                sContentType = "text/x-audiosoft-intra"
            Case "ANI"
                sContentType = "application/x-navi-animation"
            Case "AOS"
                sContentType = "application/x-nokia-9000-communicator-add-on-software"
            Case "APS"
                sContentType = "application/mime"
            Case "ART"
                sContentType = "image/x-jg"
            Case "ASM", "S"
                sContentType = "text/x-asm"
            Case "ASP"
                sContentType = "text/asp"
            Case "ASX", "ASF"
                sContentType = "video/x-ms-asf "
            Case "AU"
                sContentType = "audio/x-au"
            Case "AVI"
                sContentType = "video/msvideo"
            Case "AVS"
                sContentType = "video/avs-video"
            Case "BCPIO"
                sContentType = "application/x-bcpio"
            Case "BM", "BMP"
                sContentType = "image/bmp"
            Case "BMP"
                sContentType = "image/x-windows-bmp"
            Case "BOO", "BOOK"
                sContentType = "application/book"
            Case "BOZ", "BZ2"
                sContentType = "application/x-bzip2"
            Case "BSH", "SHAR"
                sContentType = "application/x-bsh"
            Case "BZ"
                sContentType = "application/x-bzip"
            Case "C", "C++", "CC", "CONF", "CXX", "DEF", "F", "F90", "FOR", "G", "H", "HH", "IDC", "JAV", "JAVA", "JS", "LIST", "LOG", "LST", "M", "MAR", "PL", "SDML", "TEXT", "TXT"
                sContentType = "text/plain"
            Case "CAT"
                sContentType = "application/vnd.ms-pki.seccat"
            Case "CCAD"
                sContentType = "application/clariscad"
            Case "CCO"
                sContentType = "application/x-cocoa"
            Case "CDF"
                sContentType = "application/cdf"
            Case "CER", "CRT"
                sContentType = "application/pkix-cert"
            Case "CHA", "CHAT"
                sContentType = "application/x-chat"
            Case "CLASS"
                sContentType = "application/java"
            Case "CPIO"
                sContentType = "application/x-cpio"
            Case "CPP"
                sContentType = "text/x-c"
            Case "CPT"
                sContentType = "application/mac-compactpro"
            Case "CRL"
                sContentType = "application/pkix-crl"
            Case "CSH"
                sContentType = "application/x-csh"
            Case "CSH"
                sContentType = "text/x-script.csh"
            Case "CSS"
                sContentType = "text/css"
            Case "DCR", "DIR", "DXR"
                sContentType = "application/x-director"
            Case "DEEPV"
                sContentType = "application/x-deepv"
            Case "DER"
                sContentType = "application/x-x509-ca-cert"
            Case "DIF", "DV"
                sContentType = "video/x-dv"
            Case "DL"
                sContentType = "video/dl"
            Case "DOC", "DOT", "W6W", "WIZ", "WORD"
                sContentType = "application/msword"
            Case "DP"
                sContentType = "application/commonground"
            Case "DRW"
                sContentType = "application/drafting"
            Case "DVI"
                sContentType = "application/x-dvi"
            Case "DWF"
                sContentType = "model/vnd.dwf"
            Case "DWG", "DXF", "SVF"
                sContentType = "image/vnd.dwg"
            Case "EL"
                sContentType = "text/x-script.elisp"
            Case "ELC"
                sContentType = "application/x-elc"
            Case "ENV"
                sContentType = "application/x-envoy"
            Case "ES"
                sContentType = "application/x-esrehber"
            Case "ETX"
                sContentType = "text/x-setext"
            Case "EVY"
                sContentType = "application/envoy"
            Case "F77"
                sContentType = "text/x-fortran"
            Case "FDF"
                sContentType = "application/vnd.fdf"
            Case "FIF"
                sContentType = "image/fif"
            Case "FLI"
                sContentType = "video/fli"
            Case "FLO", "TURBOT            image/florian"
            Case "FLX"
                sContentType = "text/vnd.fmi.flexstor"
            Case "FMF"
                sContentType = "video/x-atomic3d-feature"
            Case "FPX"
                sContentType = "image/vnd.fpx"
            Case "FRL"
                sContentType = "application/freeloader"
            Case "FUNK", "MY", "PFUNK"
                sContentType = "audio/make"
            Case "G3"
                sContentType = "image/g3fax"
            Case "GIF"
                sContentType = "image/gif"
            Case "GL"
                sContentType = "video/gl"
            Case "GSD", "GSM"
                sContentType = "audio/x-gsm"
            Case "GSP"
                sContentType = "application/x-gsp"
            Case "GSS"
                sContentType = "application/x-gss"
            Case "GTAR"
                sContentType = "application/x-gtar"
            Case "GZ", "GZIP"
                sContentType = "application/x-gzip"
            Case "HDF"
                sContentType = "application/x-hdf"
            Case "HELP"
                sContentType = "application/x-helpfile"
            Case "HGL", "HPG", "HPGL"
                sContentType = "application/vnd.hp-hpgl"
            Case "HLB"
                sContentType = "text/x-script"
            Case "HLP"
                sContentType = "application/hlp"
            Case "HQX"
                sContentType = "application/binhex"
            Case "HTA"
                sContentType = "application/hta"
            Case "HTC"
                sContentType = "text/x-component"
            Case "HTT"
                sContentType = "text/webviewhtml"
            Case "ICE"
                sContentType = "x-conference/x-cooltalk"
            Case "ICO"
                sContentType = "image/x-icon"
            Case "IEF", "IEFS"
                sContentType = "image/ief"
            Case "IGES", "IGS"
                sContentType = "model/iges"
            Case "IMA"
                sContentType = "application/x-ima"
            Case "IMAP"
                sContentType = "application/x-httpd-imap"
            Case "INF"
                sContentType = "application/inf"
            Case "INS"
                sContentType = "application/x-internett-signup"
            Case "IP"
                sContentType = "application/x-ip2"
            Case "ISU"
                sContentType = "video/x-isvideo"
            Case "IT"
                sContentType = "audio/it"
            Case "IV"
                sContentType = "application/x-inventor"
            Case "IVR"
                sContentType = "i-world/i-vrml"
            Case "IVY"
                sContentType = "application/x-livescreen"
            Case "JAM"
                sContentType = "audio/x-jam"
            Case "JCM"
                sContentType = "application/x-java-commerce"
            Case "JFIF", "JFIF-TBNL", "JPE", "JPEG", "JPG"
                sContentType = "image/jpeg"
            Case "JPS"
                sContentType = "image/x-jps"
            Case "JUT"
                sContentType = "image/jutvision"
            Case "KAR", "MID", "MIDI"
                sContentType = "audio/midi"
            Case "KSH"
                sContentType = "text/x-script.ksh"
            Case "LA"
                sContentType = "audio/x-nspaudio"
            Case "LA", "LMA"
                sContentType = "audio/nspaudio"
            Case "LAM"
                sContentType = "audio/x-liveaudio"
            Case "LATEX", "LTX"
                sContentType = "application/x-latex"
            Case "LSP"
                sContentType = "text/x-script.lisp"
            Case "LSX"
                sContentType = "text/x-la-asf"
            Case "M1V", "M2V", "MP2", "MP3", "MPA", "MPE", "MPEG", "MPG"
                sContentType = "video/mpeg"
            Case "M2A", "MP2", "MPGA"
                sContentType = "audio/mpeg"
            Case "M3U"
                sContentType = "audio/x-mpequrl"
            Case "MAN"
                sContentType = "application/x-troff-man"
            Case "MAP"
                sContentType = "application/x-navimap"
            Case "MBD"
                sContentType = "application/mbedlet"
            Case "MC$"
                sContentType = "application/x-magic-cap-package-1.0"
            Case "MCD"
                sContentType = "application/mcad"
            Case "MCF"
                sContentType = "text/mcf"
            Case "MCP"
                sContentType = "application/netmc"
            Case "ME"
                sContentType = "application/x-troff-me"
            Case "MHT", "MHTML", "MIME"
                sContentType = "message/rfc822"
            Case "MIF"
                sContentType = "application/x-frame"
            Case "MJF"
                sContentType = "audio/x-vnd.audioexplosion.mjuicemediafile"
            Case "MJPG"
                sContentType = "video/x-motion-jpeg"
            Case "MM", "MME"
                sContentType = "application/base64"
            Case "MOD"
                sContentType = "audio/mod"
            Case "MOOV", "MOV", "QT"
                sContentType = "video/quicktime"
            Case "MOVIE", "MV"
                sContentType = "video/x-sgi-movie"
            Case "MPC", "MPT", "MPV", "MPX"
                sContentType = "application/x-project"
            Case "MPP"
                sContentType = "application/vnd.ms-project"
            Case "MRC"
                sContentType = "application/marc"
            Case "MS"
                sContentType = "application/x-troff-ms"
            Case "MZZ"
                sContentType = "application/x-vnd.audioexplosion.mzz"
            Case "NAP", "NAPLPS            image/naplps"
            Case "NC"
                sContentType = "application/x-netcdf"
            Case "NCM"
                sContentType = "application/vnd.nokia.configuration-message"
            Case "NIF", "NIFF"
                sContentType = "image/x-niff"
            Case "NIX"
                sContentType = "application/x-mix-transfer"
            Case "NSC"
                sContentType = "application/x-conference"
            Case "NVD"
                sContentType = "application/x-navidoc"
            Case "ODA"
                sContentType = "application/oda"
            Case "OMC"
                sContentType = "application/x-omc"
            Case "OMCD"
                sContentType = "application/x-omcdatamaker"
            Case "OMCR"
                sContentType = "application/x-omcregerator"
            Case "P"
                sContentType = "text/x-pascal"
            Case "P10"
                sContentType = "application/pkcs10"
            Case "P12"
                sContentType = "application/pkcs-12"
            Case "P7A"
                sContentType = "application/x-pkcs7-signature"
            Case "P7C", "P7M"
                sContentType = "application/pkcs7-mime"
            Case "P7R"
                sContentType = "application/x-pkcs7-certreqresp"
            Case "P7S"
                sContentType = "application/pkcs7-signature"
            Case "PART", "PRT"
                sContentType = "application/pro_eng"
            Case "PAS"
                sContentType = "text/pascal"
            Case "PBM"
                sContentType = "image/x-portable-bitmap"
            Case "PCL"
                sContentType = "application/vnd.hp-pcl"
            Case "PCT"
                sContentType = "image/x-pict"
            Case "PCX"
                sContentType = "image/x-pcx"
            Case "PDB", "XYZ"
                sContentType = "chemical/x-pdb"
            Case "PDF"
                sContentType = "application/pdf"
            Case "PGM"
                sContentType = "image/x-portable-greymap"
            Case "PIC", "PICT"
                sContentType = "image/pict"
            Case "PKG"
                sContentType = "application/x-newton-compatible-pkg"
            Case "PKO"
                sContentType = "application/vnd.ms-pki.pko"
            Case "PLX"
                sContentType = "application/x-pixclscript"
            Case "PM"
                sContentType = "text/x-script.perl-module"
            Case "PM4", "PM5"
                sContentType = "application/x-pagemaker"
            Case "PNG", "X-PNG"
                sContentType = "image/png"
            Case "PNM"
                sContentType = "image/x-portable-anymap"
            Case "POT", "PPA", "PPS", "PPT", "PPZ", "PWZ"
                sContentType = "application/powerpoint"
            Case "POV"
                sContentType = "model/x-pov"
            Case "PPM"
                sContentType = "image/x-portable-pixmap"
            Case "PRE"
                sContentType = "application/x-freelance"
            Case "PVU"
                sContentType = "paleovu/x-pv"
            Case "PY"
                sContentType = "text/x-script.phyton"
            Case "PYC"
                sContentType = "applicaiton/x-bytecode.python"
            Case "QCP"
                sContentType = "audio/vnd.qcelp"
            Case "QIF", "QTI", "QTIF"
                sContentType = "image/x-quicktime"
            Case "QTC"
                sContentType = "video/x-qtc"
            Case "RA"
                sContentType = "audio/x-realaudio"
            Case "RA", "RAM", "RM", "RMM", "RMP"
                sContentType = "audio/x-pn-realaudio"
            Case "RAS", "RAST"
                sContentType = "image/cmu-raster"
            Case "REXX"
                sContentType = "text/x-script.rexx"
            Case "RF"
                sContentType = "image/vnd.rn-realflash"
            Case "RGB"
                sContentType = "image/x-rgb"
            Case "RMI"
                sContentType = "audio/mid"
            Case "RNG"
                sContentType = "application/ringing-tones"
            Case "RNX"
                sContentType = "application/vnd.rn-realplayer"
            Case "ROFF"
                sContentType = "application/x-troff"
            Case "RP"
                sContentType = "image/vnd.rn-realpix"
            Case "RPM"
                sContentType = "audio/x-pn-realaudio-plugin"
            Case "RT", "RTF", "RTX"
                sContentType = "text/richtext"
            Case "RV"
                sContentType = "video/vnd.rn-realvideo"
            Case "S3M"
                sContentType = "audio/s3m"
            Case "SBK"
                sContentType = "application/x-tbook"
            Case "SCM"
                sContentType = "application/x-lotusscreencam"
            Case "SDP"
                sContentType = "application/sdp"
            Case "SDR"
                sContentType = "application/sounder"
            Case "SEA"
                sContentType = "application/sea"
            Case "SET"
                sContentType = "application/set"
            Case "SGM", "SGML"
                sContentType = "text/sgml"
            Case "SH"
                sContentType = "application/x-sh"
            Case "SID"
                sContentType = "audio/x-psid"
            Case "SIT"
                sContentType = "application/x-sit"
            Case "SKD", "SKM", "SKP", "SKT"
                sContentType = "application/x-koan"
            Case "SL"
                sContentType = "application/x-seelogo"
            Case "SMI", "SMIL"
                sContentType = "application/smil"
            Case "SND"
                sContentType = "audio/basic"
            Case "SOL"
                sContentType = "application/solids"
            Case "SPC"
                sContentType = "application/x-pkcs7-certificates"
            Case "SPL"
                sContentType = "application/futuresplash"
            Case "SPR", "SPRITE            application/x-sprite"
            Case "SRC", "WSRC"
                sContentType = "application/x-wais-source"
            Case "SSI"
                sContentType = "text/x-server-parsed-html"
            Case "SSM"
                sContentType = "application/streamingmedia"
            Case "SST"
                sContentType = "application/vnd.ms-pki.certstore"
            Case "STEP", "STP"
                sContentType = "application/step"
            Case "STL"
                sContentType = "application/sla"
            Case "SV4CPIO            application/x-sv4cpio"
            Case "SV4CRC            application/x-sv4crc"
            Case "SVR"
                sContentType = "application/x-world"
            Case "SWF"
                sContentType = "application/x-shockwave-flash"
            Case "T"
                sContentType = "application/x-troff"
            Case "TALK"
                sContentType = "text/x-speech"
            Case "TAR"
                sContentType = "application/x-tar"
            Case "TBK"
                sContentType = "application/toolbook"
            Case "TCL"
                sContentType = "application/x-tcl"
            Case "TCSH"
                sContentType = "text/x-script.tcsh"
            Case "TEX"
                sContentType = "application/x-tex"
            Case "TEXI", "TEXINFO            application/x-texinfo"
            Case "TGZ"
                sContentType = "application/gnutar"
            Case "TIF", "TIFF"
                sContentType = "image/tiff"
            Case "TR"
                sContentType = "application/x-troff"
            Case "TSI"
                sContentType = "audio/tsp-audio"
            Case "TSP"
                sContentType = "audio/tsplayer"
            Case "TSV"
                sContentType = "text/tab-separated-values"
            Case "UIL"
                sContentType = "text/x-uil"
            Case "UNI", "UNIS", "URI", "URIS"
                sContentType = "text/uri-list"
            Case "UNV"
                sContentType = "application/i-deas"
            Case "USTAR"
                sContentType = "application/x-ustar"
            Case "UU", "UUE"
                sContentType = "text/x-uuencode"
            Case "VCD"
                sContentType = "application/x-cdlink"
            Case "VCS"
                sContentType = "text/x-vcalendar"
            Case "VDA"
                sContentType = "application/vda"
            Case "VDO"
                sContentType = "video/vdo"
            Case "VEW"
                sContentType = "application/groupwise"
            Case "VIV", "VIVO"
                sContentType = "video/vivo"
            Case "VMD"
                sContentType = "application/vocaltec-media-desc"
            Case "VMF"
                sContentType = "application/vocaltec-media-file"
            Case "VOC"
                sContentType = "audio/voc"
            Case "VOS"
                sContentType = "video/vosaic"
            Case "VOX"
                sContentType = "audio/voxware"
            Case "VQE", "VQL"
                sContentType = "audio/x-twinvq-plugin"
            Case "VQF"
                sContentType = "audio/x-twinvq"
            Case "VRML", "WRL", "WRZ"
                sContentType = "model/vrml"
            Case "VRT"
                sContentType = "x-world/x-vrt"
            Case "VSD", "VST", "VSW"
                sContentType = "application/x-visio"
            Case "W60"
                sContentType = "application/wordperfect6.0"
            Case "W61"
                sContentType = "application/wordperfect6.1"
            Case "WAV"
                sContentType = "audio/wav"
            Case "WAX"
                sContentType = "audio/x-ms-wax "
            Case "WB1"
                sContentType = "application/x-qpro"
            Case "WBMP"
                sContentType = "image/vnd.wap.wbmp"
            Case "WEB"
                sContentType = "application/vnd.xara"
            Case "WK1"
                sContentType = "application/x-123"
            Case "WM"
                sContentType = "video/x-ms-wm "
            Case "WMA"
                sContentType = "audio/x-ms-wma "
            Case "WMD"
                sContentType = "application/x-ms-wmd "
            Case "WMF"
                sContentType = "windows/metafile"
            Case "WML"
                sContentType = "text/vnd.wap.wml"
            Case "WMLC"
                sContentType = "application/vnd.wap.wmlc"
            Case "WMLS"
                sContentType = "text/vnd.wap.wmlscript"
            Case "WMLSC"
                sContentType = "application/vnd.wap.wmlscriptc"
            Case "WMV"
                sContentType = "video/x-ms-wmv "
            Case "WMX"
                sContentType = "video/x-ms-wmx "
            Case "WMZ"
                sContentType = "application/x-ms-wmz "
            Case "WP", "WP5", "WP6", "WPD"
                sContentType = "application/wordperfect"
            Case "WQ1"
                sContentType = "application/x-lotus"
            Case "WRI"
                sContentType = "application/mswrite"
            Case "WSC"
                sContentType = "text/scriplet"
            Case "WTK"
                sContentType = "application/x-wintalk"
            Case "WVX"
                sContentType = "video/x-ms-wvx "
            Case "XBM", "XPM"
                sContentType = "image/xpm"
            Case "XDR"
                sContentType = "video/x-amt-demorun"
            Case "XGZ"
                sContentType = "xgl/drawing"
            Case "XIF"
                sContentType = "image/vnd.xiff"
            Case "XL", "XLA", "XLB", "XLC", "XLD", "XLK", "XLL", "XLM", "XLS", "XLT", "XLV", "XLW"
                sContentType = "application/excel"
            Case "XM"
                sContentType = "audio/xm"
            Case "XML"
                sContentType = "application/xml"
            Case "XMZ"
                sContentType = "xgl/movie"
            Case "XPIX"
                sContentType = "application/x-vnd.ls-xpix"
            Case "XSR"
                sContentType = "video/x-amt-showrun"
            Case "XWD"
                sContentType = "image/x-xwd"
            Case "Z"
                sContentType = "application/x-compressed"
            Case "ZIP"
                sContentType = "application/zip"
            Case "ZSH"
                sContentType = "text/x-script.zsh"
            Case Else
                sContentType = "application/octet-stream"
        End Select

        If Left(sContentType, InStr(1, sContentType, "/", vbTextCompare) - 1) Then
            lStreamType = adTypeText
        Else
            lStreamType = adTypeBinary
        End If

        Response.ContentType = sContentType

        '   open a stream
        Set objStream = Server.CreateObject("ADODB.Stream")
        objStream.Open

        '   set type
        objStream.Type = lStreamType
<snip>
(assuption: variables DIMed, adType-constants defined)
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 7

Expert Comment

by:Hecatonchires
ID: 16978484
That'd... pretty much do it.  Maybe encapsulise it in a function so that your code is neater.

The windows filesystem doesn't seem to keep a real mime-type, just extensions. - its very 'bolted on' the side.  (Unlike the old mac and beos fs's)
0
 
LVL 7

Expert Comment

by:Hecatonchires
ID: 16978485
and i should have done the right in the first comment better...
0
 

Author Comment

by:WebJoe
ID: 16978851
Too bad, but thanks for you effort
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

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…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

630 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