Bonjour,

J'essai de lire un fichier ligne par ligne en récupérant son chemin , mais j'ai toujours une exception qui ça affiche au niveau : de la ligne
Code : Sélectionner tout - Visualiser dans une fenêtre à part
string[] lines = System.IO.File.ReadAllLines(pathfile + openFileDialog1.FileName);
Le format du chemin d'accès donné n'est pas pris en charge.

Mon code est le suivant:
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
 OpenFileDialog openFileDialog1 = new OpenFileDialog();
 
            // Set filter options and filter index.
            openFileDialog1.Filter = "Text Files (.txt)|*.txt|All Files (*.*)|*.*";
            openFileDialog1.FilterIndex = 1;
 
            openFileDialog1.Multiselect = true;
 
 
            // Process input if the user clicked OK.
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                // Open the selected file to read.
                System.IO.Stream fileStream = openFileDialog1.OpenFile();
                if ((fileStream = openFileDialog1.OpenFile()) != null)
                {
                    using (fileStream)
                    {
                        string sFileName = openFileDialog1.FileName;
                        string pathfile = string.Format("{0}/{1}", Path.GetDirectoryName(sFileName), sFileName);
                        string directoryPath = Path.GetDirectoryName(pathfile);
                        System.IO.FileInfo fInfo = new System.IO.FileInfo(sFileName);
 
                        string strFileName = fInfo.Name;
 
                        string strFilePath = fInfo.DirectoryName;
                        string[] lines = System.IO.File.ReadAllLines(pathfile + openFileDialog1.FileName);
                        foreach (string line in lines)
                        {
                            // Use a tab to indent each line of the file.
                            MessageBox.Show("\t" + line);
                        }
                    }
                }
J'arrive pas à voir le problème.
Pourriez-vous m'aider SVP?
Merci!