Visualizzazione dei risultati da 1 a 9 su 9
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    40

    OpenFile,FileGet, un aiuto in .NET

    Devo realizzare un applicazione che legge i file.txt contenuti in una certalla.
    Questi file devono essere aperti, ogni riga devo essere copiata in una stringa. ogni stringa verrà separata in più stringhe che rappresentano campi di un mio database.
    Questo database verrà aggiornato.
    Non so da dove cominciare...
    Non sarò mai come Alfa!!!

  2. #2
    intanto devi importarti la classe I/O
    <%@ Import Namespace="System.IO" %>

    poi ti apri il tuo bel file
    dim objReader as New StreamReader(Server.MapPath("public/messaggi.txt"))

    poi per scorrere il file fai cosi:
    while objReader.Peek() >-1 'quando arriva a fine file restituisce -1
    tua_stringa = objReader.ReadLine
    'qui fai le operazioni sulle stringhe
    end while
    objReader.Close

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    40

    Grazie Mille!!!

    Grazie mille, sei un dio.
    Se ho bisogno posso chiederti ancora?
    ciao?
    Non sarò mai come Alfa!!!

  4. #4
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    40

    Recor per record

    come posso fare per leggere un record fino a un tot che decido io?
    ad esempio. dalla lettere in posizione 1 alla 5 poi dalla 6 alle 15 etc..
    Non sarò mai come Alfa!!!

  5. #5
    objReader.Read(stringa, inizio, numero_caratteri)

    questa istruzione legge il numero di caratteri "numero_caratteri" da inizio e l'output te lo emtte in stringa

  6. #6
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    40

    non riesco

    ho messo:
    Sub leggi_record()
    Dim objReader As New StreamReader(Server.MapPath("FL13R42.21_200335.txt "))
    Dim tua_stringa As String
    'poi per scorrere il file:
    While objReader.Peek() > -1 'quando arriva a fine file restituisce -1
    tua_stringa = objReader.Read(tua_stringa, 1, 5)
    End While
    objReader.Close()
    FileClose(1)
    Response.Write(tua_stringa)
    End Sub


    non funge
    Non sarò mai come Alfa!!!

  7. #7
    teoricamente dovrebbe essere cosi:
    codice:
    Sub leggi_record() 
      Dim objReader As New StreamReader(Server.MapPath("FL13R42.21_200335.txt")) 
      Dim tua_stringa As String 
    'poi per scorrere il file: 
      While objReader.Peek() > -1 'quando arriva a fine file restituisce -1 
         tua_stringa = objReader.Read(tua_stringa, 1, 5) 
         Response.Write(tua_stringa)
      End While 
      objReader.Close() 
      FileClose(1) 
     
    End Sub
    ma ricevi un errore? dimmi qualcosa non ho la palla di vetro.

  8. #8
    Utente di HTML.it
    Registrato dal
    May 2003
    Messaggi
    40
    Server Error in '/FileExplorer' Application.
    --------------------------------------------------------------------------------

    Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.ArgumentException:
    Source Error:


    Line 34: 'poi per scorrere il file:
    Line 35: 'While objReader.Peek() > -1 'quando arriva a fine file restituisce -1
    Line 36: tua_stringa = objReader.Read(tua_stringa, 0, 2)
    Line 37: 'End While
    Line 38: objReader.Close()

    Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.
    Non sarò mai come Alfa!!!

  9. #9
    l'errore se non sbaglio vuol dire che va fuori indice cioè la grandezza da te richiesta è + grande di quella dovuta.

    Praticamente se tu hai la stringa 12345 e chiedi di andare da 1 a 7 vai "out of bounds"


    PS prova ad aprire il file cosi:
    dim fs as new FileStream(Server.MapPath("FL13R42.21_200335.txt") ,FileMode.Open,FileAccess.Read)
    dim objReader as new StreamReader(fs)

    While objReader.Peek() > -1
    tua_stringa = objReader.Read(tua_stringa, 0, 2)
    End While

    o prova pure cosi:

    While objReader.Peek() > -1
    tua_stringa = objReader.ReadLine(tua_stringa, 0, 2)
    End While

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.