나는 목록 상자가 있으며 디렉토리 폴더에서로드 된 일부 파일이 있습니다.목록 상자에서 파일을 찾을 수 없습니다. C# win forms
코드는에 ListBox1에 파일을로드 :
private void Form1_Load(object sender, EventArgs e)
{
PopulateListBox(listbox1, @"C:\TestLoadFiles", "*.rtld");
}
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.Name);
}
}
내가 읽고 형태로 라벨에 속성 값을 표시합니다. listBox1
에로드 된 파일은 여기에 코드입니다 : 내가 폼이로드 된 후에 ListBox1에서 파일을 클릭하면
private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
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
}
}
}
}
Problem:
이 파일이 목록 상자에 폴더에서로드하지만 오류를 던지고 File not found in the directory
.
이 문제를 어떻게 해결할 수 있습니까 ???
난 그냥 화면을 파일 이름을 추가하고 파일을 읽고 싶어. – linguini
@KarthikRANGARAJ, 나는 당신을 얻지 못했습니다. 이름 만 보여주고 전체 이름을 표시하여 파일을 표시하겠습니까? – Habib
listBox1에서 폴더의'파일 이름 '만 표시하면됩니다. 클릭하면 해당 파일의 속성 값을 레이블로 읽어야합니다. – linguini