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(); } }
Partager