Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 12

Discussione: Un piccolo quesito

  1. #1

    Un piccolo quesito

    Salve, ho appena terminato di scrivere una pagina ASP contenente, tra l'altro, anche un campo OLE contenente un file scelto dall'utente che utilizza il modulo di contatto, scegliendo un file dal suo pc. Ed il tutto funziona bene (verificato).

    I fields del db che interessano il campo OLE, chiaramente oltre a quest'ultimo, sono i seguenti:

    SourceFileName : il nome del file completo (EXE, BMP, ZIP, ecc...)
    ContentType : che può essere application/octet-stream oppure application/x-zip-compressed ecc.
    DataSize : che sarebbe la lunghezza effettiva del file stored
    Data : che è il file stesso conservato nel campo OLE.

    Ora però che devo recuperare il file dal database e lo devo scrivere in una cartella in locale, mi trovo in difficoltà.

    Chi mi può aiutare ?

  2. #2
    codice:
    Response.BinaryWrite rs("nomeCampo")
    http://www.google.it/search?q=Respon...ient=firefox-a

  3. #3
    Basta solo questo ?? Sicuro ??
    Pensavo ci volessero anche
    codice:
    Response.ContentType = ContentType
    Response.AddHeader "Content-Disposition", "attachment; filename=""" & outFileName & """"
    Response.BinaryWrite OutByteArray.ByteArray
    Grazie comunque

  4. #4
    Ovvio che ci vuole anche quello.
    Comunque, leggi la ricerca su Google.

  5. #5
    Ciao, ci ho lavorato ed ho seguito la ricerca che mi hai consigliato.

    Ho scritto un po' di codice, dai un'occhiata e dimmi se puo' funzionare:

    codice:
    <%
    Sub PrelevaRecord(Record)
      sSQL="Select cognome, nome, SourceFileName, ContentType, DataSize, Data from Upload where UploadID=" & Record 
      rs.Open sSQL, GetConnection,3,3 
      FolderName = Server.MapPath("/public") & "\" & LCase(rs("cognome")) & "-" & LCase(rs("nome"))
      IF NOT FolderFind(FolderName) THEN
         Set FS = CreateObject("scripting.filesystemobject")
         Set TempFolder = FS.CreateFolder(FolderName)
         Set FS = Nothing
      END IF
      sFileName = TempFolder & "\" & rs("SourceFileName")
      dim oStr 
      set oStr=server.CreateObject("ADODB.Stream") 
      if ucase(Right(sFileName,3))="TXT" then 
         oStr.Type = 2 'text 
      else 
         oStr.Type = 1 'binary 
      end if 
      oStr.Open 
      oStr.Write rs.Fields("Data").Value 
      oStr.SaveToFile sFileName, 2 'salvo il file sul server 
      oStr.close 
      set oStr=Nothing 
      rs.Close 
    End sub
    
    Sub SpedisciFile(Record)
      sSQL="Select cognome, nome, SourceFileName, ContentType, DataSize, Data from Upload where UploadID=" & Record 
      rs.Open sSQL, GetConnection,3,3 
      FolderName = Server.MapPath("/public") & "\" & LCase(rs("cognome")) & "-" & LCase(rs("nome"))
      sFileName = TempFolder & "\" & rs("SourceFileName")
      
      set oStr=server.CreateObject("ADODB.Stream") 'riapro lo stream per spedire il file al client 
      if ucase(Right(sfilename,3))="TXT" then 
        oStr.Type = 2 'text 
      else 
        oStr.Type = 1 'binary 
      end if 
      oStr.Open 
      oStr.LoadFromFile sFileName 'carico lo stream col contenuto del file 
      Response.AddHeader "Content-Disposition", "attachment; filename=" & sFileName 
      Response.ContentType = rs("ContentType")
      Response.BinaryWrite oStr.Read 
      oStr.Close 
      Set oStr = Nothing
      Set rs = Nothing
    End Sub
    
    Function GetConnection()
      dim Conn: Set Conn = CreateObject("ADODB.Connection")
      Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
      Conn.open "Data Source=" & Server.MapPath("/mdb-database/contatti.mdb") 
    	set GetConnection = Conn
    end function
    
    Private Function FolderFind(byVal pathname)
        Dim objFSO
        Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
        FolderFind = objFSO.FolderExists(pathname)
        Set objFSO = Nothing
    End Function
    %>
    Fammi sapere e, comunque, grazie

  6. #6
    A te funziona?

  7. #7
    e non l'ho potuto ancora provare... sta' dannata connessione FastWeb !
    Stamattina non mi funziona neanche il telefono...
    Va a singhiozzo... va e viene...

    Se puoi dacci un'occhiata "accademica" al codice e fammi sapere se trovi incongruenze

  8. #8
    mems, ci sei ?
    Ho provato il codice che ho scritto.
    L'ho leggermente modificato.
    In pratica, faccio un datagrid di tutte le informazioni che sono contenute nel database e al momento di scrivere a video anche il nome del file, compongo un link in questo modo:
    Il file dowload.asp è questo:
    codice:
                 File = Request.Querystring("File")
    	Response.Buffer = True
    	Response.Clear
    	
    	sSQL="Select SourceFileName, ContentType, DataSize, Data from Upload where SourceFileName='" & File & "'" 
    	Set RS = Server.CreateObject("ADODB.Recordset")
    	RS.Open sSQL, GetConnection,3,3 
    	FolderName = Server.MapPath("/public") & "\" & "temp"
    	Set FS = CreateObject("scripting.filesystemobject")
    	TempFolder = FolderName
    	IF NOT FolderFind(FolderName) THEN
    		Set TempFolder = FS.CreateFolder(FolderName)
    	END IF
    	sFileName = TempFolder & "\" & File
    	dim oStr 
    	set oStr = server.CreateObject("ADODB.Stream") 
    	if ucase(Right(sFileName,3))="TXT" then 
    		oStr.Type = 2 'text 
    	else 
    		oStr.Type = 1 'binary 
    	end if 
    	IF NOT FS.FileExists(sFileName) THEN
    		oStr.Open 
    		oStr.Write rs.Fields("Data").Value 
    		oStr.SaveToFile sFileName, 2 'salvo il file sul server 
    	END IF
    	RS.Close
    	Set RS = Nothing
    	Set FS = Nothing
    	oStr.Close 
    	Set oStr = Nothing
    	
    '	Spedisce file
    	sSQL = "Select SourceFileName, ContentType, DataSize, Data from Upload where SourceFileName='" & File & "'" 
    	Set RS = Server.CreateObject("ADODB.Recordset")
    	RS.Open sSQL, GetConnection,3,3 
    	FolderName = Server.MapPath("/public") & "\" & "temp"
    	sFileName = TempFolder & "\" & File
    	Set FS = CreateObject("scripting.filesystemobject")
    	Set oStr = server.CreateObject("ADODB.Stream") 'riapro lo stream per spedire il file al client 
    	if ucase(Right(sFileName,3))="TXT" then 
    		oStr.Type = 2 'text 
    	else 
    		oStr.Type = 1 'binary 
    	end if 
    	oStr.Open 
    	oStr.LoadFromFile sFileName 'carico lo stream col contenuto del file
    	Response.AddHeader "Content-Disposition", "attachment; filename=" & sFileName
    	Response.ContentType = RS("ContentType")
    	Response.BinaryWrite oStr.Read
    	oStr.Close 
    	Set oStr = Nothing
    	RS.Close
    	Set RS = Nothing
    	Set FS = Nothing
    	Response.Redirect("readcontatti.asp")
    	
    Function GetConnection()
    	dim Conn: Set Conn = CreateObject("ADODB.Connection")
    	Conn.Provider = "Microsoft.Jet.OLEDB.4.0"
    	Conn.open "Data Source=" & Server.MapPath("/mdb-database/contatti.mdb") 
    	set GetConnection = Conn
    end function
    
    Private Function FolderFind(byVal pathname)
        Dim objFSO
        Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
        FolderFind = objFSO.FolderExists(pathname)
        Set objFSO = Nothing
    End Function
    Allora: il datagrid funziona, la chiamata al file download.asp funziona, i files da scaricare vengono regolarmente scritti nella cartella \public\temp (verificato con client FTP) ma.... ma non vengono caricati dal browser per il download.

    E non capisco il perché

  9. #9
    Una volta creato il file sul filesystem del sito, conoscendone il path, prova a fare un response.redirect verso il file stesso, ovviamente dopo averne verificato l'esistenza con FSO.FIleExists(server.mapPath(percorsoFile))

  10. #10
    ciao,
    a parte il fatto che ho risolto modificando il codice così:
    codice:
    Response.AddHeader "Content-Disposition", "attachment; filename=" & File
    Response.ContentType = RS("ContentType")
    Response.AddHeader "Content-Length", RS("DataSize")
    Response.BinaryWrite oStr.Read
    Response.Flush
    ma poi, tu dici che se faccio un Response.Redirect su un file che ha estensione MDB oppure ZIP o ARJ mi dovrebbe dare cosa ?

    Ciao e grazie per la risposta

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 © 2024 vBulletin Solutions, Inc. All rights reserved.