Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Sovrascrizione di un txt

    Ciao a tutti, scusate ma non sono molto pratica di vbscript e di solito lavoro con le query al database

    ho un semplicissimo guestbook che mi genera un file txt.
    Mi inserisce i commenti in maniera ascendente ma vorrei l'ultimo commento in cima ma nella generazione del txt sinceramente non so come e se si può fare...

    il codice è questo

    <%
    Else
    ' Log the entry to the guestbook file
    Dim objFSO 'FileSystemObject Variable
    Dim objFile 'File Object Variable

    ' Create an instance of the FileSystemObject
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    ' Open the TextFile (FileName, ForAppending, AllowCreation)
    Set objFile = objFSO.OpenTextFile(strFile, 8, True)

    If InStr(1, Request.Form("comment"), "http://", 1) = 0 Then
    ' Log the results
    ' I simply bold the name and do a
    .
    ' You can make it look however you'd like.
    ' Once again I remind readers that we by no means claim to
    ' be UI experts. Although one person did ask us if we had a
    ' graphic designer! I laughed so hard that I almost hurt myself!
    objFile.Write "<div style='width:100%; padding:2px; background-color:#CECECE;'>" & Date() & " - " & Time() & "</div>"
    objFile.Write "<font color=#D20707>"
    objFile.Write Server.HTMLEncode(Request.Form("name"))
    objFile.Write "</font>

    "
    objFile.Write Server.HTMLEncode(Request.Form("comment"))
    objFile.Write "

    "
    objFile.WriteLine ""
    End If

    ' Close the file and dispose of our objects
    objFile.Close
    Set objFile = Nothing
    Set objFSO = Nothing

    ' Tell people we've written their info
    %>


    Il tuo commento è stato inserito!</p>
    Torna indietro
    <%
    End If

    ' We do this to delete the file every day to keep it managable.
    ' If you were doing this for real you probably wouldn't want to
    ' do this so we have defined a const named bDeleteEntries at the
    ' top of the script that you can set to False to prevent this
    ' section from running. You could also delete this whole
    ' If Then....End If block if you'd like. Just be sure to leave
    ' the script delimiter at the bottom!
    If bDeleteEntries Then
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.GetFile(strFile)
    If DateDiff("d", objFile.DateLastModified, Date()) <> 0 Or bForce <> "" Then
    Set objFile = Nothing
    ' Can't use delete because we need the file to exist for
    ' the include the next time the script is run!
    'objFile.Delete

    ' Create a file overwriting old one.
    Set objFile = objFSO.CreateTextFile(strFile, True)

    ' The include barks if the file's empty!
    objFile.Write "Sara: "
    objFile.WriteLine "Spero che il sito vi piaccia!
    "
    objFile.Close
    End If
    Set objFile = Nothing
    Set objFSO = Nothing
    End If
    %>



    Qualcuno di voi sa aiutarmi? grassie

  2. #2
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    Ciao Sarionline,

    devi prima leggere il contenuto del file (quindi aprire il file in lettura) poi riapri il file in scrittura, ci scrivi quello che devi scrivere + quello che avevi già scritto
    codice:
    ' Create an instance of the FileSystemObject
    Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
    ' Open the TextFile (FileName, ForAppending, AllowCreation)
    Set objFile = objFSO.OpenTextFile(strFile, 1, True) 'apro in lettura
    if not objFile.AtEndOfStream then 'se il file non è vuoto
    	ContenutoFile=objFile.ReadAll 'leggo tutto e metto nella variabile ContenutoFile
    end if
    objFile.Close 
    Set objFile = objFSO.OpenTextFile(strFile, 2, True) 'apro in scrittura
    
    If InStr(1, Request.Form("comment"), "http://", 1) = 0 Then
    ' Log the results
    ' I simply bold the name and do a 
    .
    ' You can make it look however you'd like.
    ' Once again I remind readers that we by no means claim to
    ' be UI experts. Although one person did ask us if we had a
    ' graphic designer! I laughed so hard that I almost hurt myself!
    objFile.Write "<div style='width:100%; padding:2px; background-color:#CECECE;'>" & Date() & " - " & Time() & "</div>"
    objFile.Write "<font color=#D20707>"
    objFile.Write Server.HTMLEncode(Request.Form("name"))
    objFile.Write "</font>
    "
    objFile.Write Server.HTMLEncode(Request.Form("comment"))
    objFile.Write "
    
    "
    objFile.WriteLine ""
    objFile.Write ContenutoFile 'agiungo alla fine quello che era già presente nel file
    End If
    
    ' Close the file and dispose of our objects
    objFile.Close
    Set objFile = Nothing
    Set objFSO = Nothing

  3. #3

    :-))))

    grazieeeeeeeeee

    sei stato gentilissimo

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