Professional Web Applications Themes

File could not be opened - ASP Components

Hi, I have an ASP page and i want to force download an image to the user. I have the following code <% '-------------------------------------------- Response.Buffer = True Dim strFilePath, strFileSize, strFileName Const adTypeBinary = 1 strFilePath = server.mappath("\images\" & request.querystring("cat") & "\") strFileSize = 99 strFileName = request.querystring("file") Response.Clear '8*******************************8 ' Requires MDAC 2.5 to be stable ' I recommend MDAC 2.6 or 2.7 '8*******************************8 Set objStream = Server.CreateObject("ADODB.Stream") objStream.Open objStream.Type = adTypeBinary objStream.LoadFromFile strFilePath & strFileType strFileType = lcase(Right(strFileName, 4)) ' Feel Free to Add Your Own Content-Types Here Select Case strFileType Case ".gif" ContentType = "image/gif" Case ".jpg", ...

  1. #1

    Default File could not be opened

    Hi,

    I have an ASP page and i want to force download an image to the user. I have
    the following code

    <%
    '--------------------------------------------
    Response.Buffer = True
    Dim strFilePath, strFileSize, strFileName
    Const adTypeBinary = 1
    strFilePath = server.mappath("\images\" & request.querystring("cat") & "\")
    strFileSize = 99
    strFileName = request.querystring("file")
    Response.Clear
    '8*******************************8
    ' Requires MDAC 2.5 to be stable
    ' I recommend MDAC 2.6 or 2.7
    '8*******************************8
    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type = adTypeBinary
    objStream.LoadFromFile strFilePath & strFileType
    strFileType = lcase(Right(strFileName, 4))
    ' Feel Free to Add Your Own Content-Types Here
    Select Case strFileType
    Case ".gif"
    ContentType = "image/gif"
    Case ".jpg", "jpeg"
    ContentType = "image/jpeg"
    Case Else
    'Handle All Other Files
    ContentType = "application/octet-stream"
    End Select
    Response.AddHeader "Content-Disposition", "attachment; filename=" &
    strFileName
    Response.AddHeader "Content-Length", strFileSize
    ' In a Perfect World, Your Client would also have UTF-8 as the default
    ' In Their Browser
    Response.Cht = "UTF-8"
    Response.ContentType = ContentType
    Response.BinaryWrite objStream.Read
    Response.Flush
    objStream.Close
    Set objStream = Nothing
    %>

    I have checked the path that it tries to look at, and it is correct. I also
    have read and write permission on the images directory for everybody and
    anonymous internet user.

    But I still get



    Error Type:
    ADODB.Stream (0x800A0BBA)
    File could not be opened.
    /ImageBank/NewImageBank/download.asp, line 17

    What am i doing wrong?

    thanks
    panda Guest

  2. #2

    Default Re: File could not be opened


    "panda" <pandadiscussions.microsoft.com> wrote in message
    news:0F605B6B-C5AE-43EC-9C6D-808FAC60870Amicrosoft.com...
    > Hi,
    >
    > I have an ASP page and i want to force download an image to the user. I
    have
    > the following code
    >
    > <%
    > '--------------------------------------------
    > Response.Buffer = True
    > Dim strFilePath, strFileSize, strFileName
    > Const adTypeBinary = 1
    > strFilePath = server.mappath("\images\" & request.querystring("cat") &
    "\")
    > strFileSize = 99
    > strFileName = request.querystring("file")
    > Response.Clear
    > '8*******************************8
    > ' Requires MDAC 2.5 to be stable
    > ' I recommend MDAC 2.6 or 2.7
    > '8*******************************8
    > Set objStream = Server.CreateObject("ADODB.Stream")
    > objStream.Open
    > objStream.Type = adTypeBinary
    > objStream.LoadFromFile strFilePath & strFileType
    > strFileType = lcase(Right(strFileName, 4))
    > ' Feel Free to Add Your Own Content-Types Here
    > Select Case strFileType
    > Case ".gif"
    > ContentType = "image/gif"
    > Case ".jpg", "jpeg"
    > ContentType = "image/jpeg"
    > Case Else
    > 'Handle All Other Files
    > ContentType = "application/octet-stream"
    > End Select
    > Response.AddHeader "Content-Disposition", "attachment; filename=" &
    > strFileName
    > Response.AddHeader "Content-Length", strFileSize
    > ' In a Perfect World, Your Client would also have UTF-8 as the default
    > ' In Their Browser
    > Response.Cht = "UTF-8"
    > Response.ContentType = ContentType
    > Response.BinaryWrite objStream.Read
    > Response.Flush
    > objStream.Close
    > Set objStream = Nothing
    > %>
    >
    > I have checked the path that it tries to look at,
    You've done:-

    Response.Write strFilePath & strFileType
    Response.End

    Just before the LoadFromFile and seen the correct physical path?
    > and it is correct. I also
    > have read and write permission on the images directory for everybody and
    > anonymous internet user.
    Is the file read-only?

    Add the images folder as a virtual folder to the website temporarily, can
    you access the images via that virtual folder as they would in a typical
    site?


    >
    > But I still get
    >
    >
    >
    > Error Type:
    > ADODB.Stream (0x800A0BBA)
    > File could not be opened.
    > /ImageBank/NewImageBank/download.asp, line 17
    >
    > What am i doing wrong?
    >
    > thanks

    Anthony Jones Guest

  3. Moderated Post

    Default Re: File could not be opened

    Removed by Administrator
    panda Guest
    Moderated Post

  4. Moderated Post

    Default Re: File could not be opened

    Removed by Administrator
    Anthony Jones Guest
    Moderated Post

Similar Threads

  1. How to Enable Plugin before File Opened AndLoad PDF File From memory?
    By sharkmouse@adobeforums.com in forum Adobe Acrobat SDK
    Replies: 8
    Last Post: January 7th, 05:54 AM
  2. The template file could not be opened
    By pepian in forum Macromedia Exchange Dreamweaver Extensions
    Replies: 0
    Last Post: July 26th, 02:00 PM
  3. PDF file opened in Photoshop
    By Carob@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 18
    Last Post: December 29th, 10:08 AM
  4. Replies: 9
    Last Post: November 24th, 05:43 AM
  5. Product closes when file opened
    By YrbkMgr in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 0
    Last Post: August 30th, 04:37 AM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139