Précédent   Forum du club des développeurs et IT Pro > Dotnet > Développement Web avec .NET > Silverlight
Silverlight Forum d'entraide sur le développement d'applications Internet riches (RIA) avec Silverlight
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 25/12/2012, 10h35   #1
sahlyhassani007
 
Inscription : mars 2012
Messages : 17
Détails du profil
Informations forums :
Inscription : mars 2012
Messages : 17
Points : -2
Points : -2
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 :
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();
 
            }
        }
sahlyhassani007 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 14/01/2013, 07h44   #2
marquisvincent
Membre à l'essai
 
Inscription : avril 2009
Messages : 38
Détails du profil
Informations forums :
Inscription : avril 2009
Messages : 38
Points : 21
Points : 21
Quand même faut essayer de comprendre le code que l'on copie
Sinon ReadLine au lieux de ReadToEnd() dans une boucle
Cordialement
marquisvincent est déconnecté   Envoyer un message privé Réponse avec citation 10
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 11h22.


 
 
 
 
Partenaires

Hébergement Web