illegal characters in path while reading xml(.rtdl)files in C# windows forms

itsmee

New Member
In windows forms, I have some labels in the panel and I would like to display the static values from the \[code\]listBox1\[/code\] where it loads collection of (.rtdl) files from a folder. When user selects each then I want to display the corresponding attribute values to the \[code\]labels\[/code\] in the panel.Code to populate listBox1:\[code\]private void Form1_Load(object sender, EventArgs e) { PopulateListBox(listBox1, @"C:\TestLoadFiles\", "*.rtdl"); } private void PopulateListBox(ListBox lsb, string Folder, string FileType) { DirectoryInfo dinfo = new DirectoryInfo(Folder); FileInfo[] Files = dinfo.GetFiles(FileType); foreach (FileInfo file in Files) { lsb.Items.Add(file); } }\[/code\]Code to read files from the listBox1:\[code\]private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e) { FileInfo file = (FileInfo)listBox1.SelectedItem; DisplayFile(file.FullName); string path = (string)listBox1.SelectedItem; DisplayFile(path); } private void DisplayFile(string path) { string xmldoc = File.ReadAllText(path); using (XmlReader reader = XmlReader.Create(xmldoc)) { while (reader.MoveToNextAttribute()) { switch (reader.Name) { case "description": if (!string.IsNullOrEmpty(reader.Value)) label5.Text = reader.Value; // your label name break; case "sourceId": if (!string.IsNullOrEmpty(reader.Value)) label6.Text = reader.Value; // your label name break; // ... continue for each label } } } }\[/code\]When I select the file, it's throwing this error \[code\]illegal characters in path\[/code\] at \[code\]using (XmlReader reader = XmlReader.Create(xmldoc))\[/code\].Please tell me what is wrong here???
 
Back
Top