Salut,

Je cherche à modifier la ligne d'un fichier texte après un clic sur OK.
Voilà le code complet:
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
private void buttonOK_Click(object sender, EventArgs e)
        {
            string recette = textBoxSaisieRecette.Text;
            string nombreMax = textBoxSaisieNombreParCont.Text;
 
            //on remplace le nombre de BU par container            
            StreamReader reader = new StreamReader("Recettes_BU.txt");
            string ligneLue;
            do
            {
                ligneLue = reader.ReadLine();
                if (ligneLue == textBoxSaisieRecette.Text)
                {
                    //on se décale de 2 lignes plus bas
                    ligneLue = reader.ReadLine();
                    ligneLue = reader.ReadLine();
 
                    //on remplace la ligne
                    ligneLue = ligneLue.Replace(ligneLue, textBoxSaisieNombreParCont.Text);
                    break;
                }
            } while ((ligneLue != null) || (ligneLue != textBoxSaisieRecette.Text));
            reader.Close();
        }

Ce code ne marche pas, le fichier texte n'est pas mis à jour.