我有一个列表框,它由这种方法填充,
private void ToReadFromExcel_Load(object sender, EventArgs e)
{
string folderpath = @"\\gibson\users";
// Call the method to show available files
PopulateListBox(ExcelListBox, folderpath, "*.csv");
}
// To populate list box with csv files from given path
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);
}
}
String strItem;
foreach (Object selecteditem in ExcelListBox.SelectedItems)
{
strItem = selecteditem as String;
MessageBox.Show(strItem);
}
// read csv file information and insert into detail table
string filepath = @"\\gibson\users\CampManager.csv";
StreamReader sr = new StreamReader(filepath);
我现在对文件路径进行了硬编码,但我需要传递在列表框中选择的文件路径。我在变量中有文件名stritem
。如果我想传递整个文件夹路径,我该怎么做?