IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Silverlight Discussion :

lire un fichier text


Sujet :

Silverlight

  1. #1
    Membre à l'essai
    Inscrit en
    Mars 2012
    Messages
    21
    Détails du profil
    Informations forums :
    Inscription : Mars 2012
    Messages : 21
    Points : 10
    Points
    10
    Par défaut lire un fichier text
    Bonjour je veut extracter les donees dans un fichier text :

    fichier.txt

    1|xxx|yyy|[m]
    2|rrr|hhh|[f]

    Comment passer du 1er etudiant au 2eme pour l ajouter dans la base de donnée

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
     
     private void bOpenFileDialog_Click(object sender, RoutedEventArgs e)
            {
                // Create an instance of the open file dialog box.
                OpenFileDialog openFileDialog1 = new OpenFileDialog();
     
                // Set filter options and filter index.
                openFileDialog1.Filter = "Text Files (.txt)|*.txt|All Files (*.*)|*.*";
                openFileDialog1.FilterIndex = 1;
     
                openFileDialog1.Multiselect = true;
     
                // Call the ShowDialog method to show the dialog box.
                bool? userClickedOK = openFileDialog1.ShowDialog();
     
                // Process input if the user clicked OK.
                if (userClickedOK == true)
                {
                    // Open the selected file to read.
                    System.IO.Stream fileStream = openFileDialog1.File.OpenRead();
     
                    using (System.IO.StreamReader reader = new System.IO.StreamReader(fileStream))
                    {
                        // Read the first line from the file and write it the textbox.
                        char[] splitchar = { ' ' };
                        string[] mots = reader.ReadToEnd().Split(splitchar);
                       // tbResults.Text = reader.ReadToEnd();
                        foreach (String mot in mots)
                            tbResults.Text ="\n"+ mot;
                        listBox1.ItemsSource = mots;
     
                        ServiceReference1.WebServiceAlerteSoapClient s = new ServiceReference1.WebServiceAlerteSoapClient();
                        ServiceReference1.etudiant a = new ServiceReference1.etudiant();
                        a.id=mots[0];
                        a.nom = mots[1];
                        a.prenom = mots[2];
                        a.sexe=mots[3];
     
                        s.AddEtudAsync(a);
     
     
                    }
                    fileStream.Close();
     
                }
            }

  2. #2
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2009
    Messages
    37
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2009
    Messages : 37
    Points : 38
    Points
    38
    Par défaut
    Quand même faut essayer de comprendre le code que l'on copie
    Sinon ReadLine au lieux de ReadToEnd() dans une boucle
    Cordialement

Discussions similaires

  1. Réponses: 2
    Dernier message: 05/12/2005, 16h57
  2. [Applet] lire un fichier texte
    Par lebesnec dans le forum Applets
    Réponses: 2
    Dernier message: 07/07/2005, 11h09
  3. Réponses: 1
    Dernier message: 24/11/2004, 17h54
  4. [Fichier] Lire un fichier texte long
    Par _Eric_ dans le forum Entrée/Sortie
    Réponses: 9
    Dernier message: 18/08/2004, 16h22
  5. Réponses: 2
    Dernier message: 26/05/2004, 18h53

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo