Visualizzazione dei risultati da 1 a 4 su 4

Discussione: download file pdf

  1. #1

    download file pdf

    Ciao, in asp come posso fare il download di un file pdf ?

  2. #2
    cerca nel forum "download forzato"


  3. #3
    La ricerca purteoppo e ancora sospesa per manutenzione (supongo)

  4. #4
    codice:
    '-- do some basic error checking for the QueryString
    If strPath = "" Then
      Response.Clear
      Response.Write("Impossibile effettuare il download : nessun file speficicato.")
      Response.End
    ElseIf InStr(strPath, "..") > 0 Then
      Response.Clear
      Response.Write("Impossibile effettuare il download : percorso non valido.")
      Response.End
    ElseIf Len(strPath) > 1024 Then
      Response.Clear
      Response.Write("Impossibile effettuare il download : percorso troppo lungo.")
      Response.End
    Else
      Call DownloadFile(strPath)
    End If
      
    Private Sub DownloadFile(file)
      '--declare variables
      Dim strAbsFile
      Dim strFileExtension
      Dim objFSO
      Dim objFile
      Dim objStream
      '-- set absolute file location
      strAbsFile = Server.MapPath(file)
      '-- create FSO object to check if file exists and get properties
      Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
      '-- check to see if the file exists
      If objFSO.FileExists(strAbsFile) Then
        Set objFile = objFSO.GetFile(strAbsFile)
          '-- first clear the response, and then set the appropriate headers
          Response.Clear
          '-- the filename you give it will be the one that is shown
          '   to the users by default when they save
          Response.AddHeader "Content-Disposition", "attachment; filename=" & objFile.Name
          Response.AddHeader "Content-Length", objFile.Size
          Response.ContentType = "application/octet-stream"
          Set objStream = Server.CreateObject("ADODB.Stream")
            objStream.Open
            '-- set as binary
            objStream.Type = 1
            Response.CharSet = "UTF-8"
            '-- load into the stream the file
            objStream.LoadFromFile(strAbsFile)
            '-- send the stream in the response
            Response.BinaryWrite(objStream.Read)
            objStream.Close
          Set objStream = Nothing
        Set objFile = Nothing
      Else  'objFSO.FileExists(strAbsFile)
        Response.Clear
        Response.Write("Impossibile effettuare il download : file non esistente.")
      End If
      Set objFSO = Nothing
    End Sub
    Putroppo non ricordo la fonte (forse ASP101?), cmq potrebbe esserci qualche piccola modifica dall'originale...
    Funziona con qualsiasi tipo di file

    Ciau
    - Atari

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.