download file with [1] at the end of the file name

Discussion in 'ASP General' started by Michel, Jul 15, 2004.

  1. Michel

    Michel Guest

    Hi,
    I've the code bellow who give me a file to download.
    The files are sored in a folder. The filename is the id of the data stored
    in a table.
    The name of the file at the download time will be the one stored in the
    table.
    The problem is that if the file name in the table is toto.doc the browser
    propose me to save it at toto.doc[1]
    How can I get rid of the [1]
    The file can be of any tipe.

    <!--#include file="header.inc"-->
    <%
    dim fileId
    dim fileName
    dim path
    dim sql
    dim rs
    dim objFSO
    dim objFile
    dim objStream

    fileId = Request.QueryString("fileId")

    sql = "select * from file where id_file = " & fileId
    set rs = Server.CreateObject("ADODB.Recordset")
    Call rs.Open(sql, conn, adOpenStatic, adLockReadOnly)
    fileName = rs("fileName")
    path = Server.MapPath("file") & "\"

    set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    If objFSO.FileExists(path & fileId) Then
    Set objFile = objFSO.GetFile(path & fileId)
    ' write header
    Response.Clear
    Response.AddHeader "Content-Disposition", "attachment; filename=" &
    Server.URLEncode(fileName)
    Response.AddHeader "Content-Length", objFile.Size
    Response.ContentType = "application/octet-stream"
    ' get the data
    Set objStream = Server.CreateObject("ADODB.Stream")
    objStream.Open
    objStream.Type = 1 'adTypeBinary
    Response.CharSet = "UTF-8"
    objStream.LoadFromFile(path & fileId)
    Response.BinaryWrite(objStream.Read)
    objStream.Close
    Set objStream = Nothing
    Set objFile = Nothing
    else
    %>
    <html>
    <body>
    <h1>File not found</h1>
    </body>
    </html>
    <%
    end if
    set objFSO = Nothing
    %>
    Michel, Jul 15, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryan Taylor
    Replies:
    2
    Views:
    941
    Ryan Taylor
    Nov 10, 2004
  2. Sam --
    Replies:
    2
    Views:
    604
    Sam --
    Mar 17, 2005
  3. Brett  Kelly
    Replies:
    1
    Views:
    676
    Steve C. Orr [MVP, MCSD]
    Jun 16, 2006
  4. Jimmy
    Replies:
    3
    Views:
    325
    J. J. Farrell
    Sep 9, 2011
  5. Jimmy
    Replies:
    13
    Views:
    648
    Peter Nilsson
    Sep 21, 2011
Loading...

Share This Page