一个用asp.net(c#)编写程序得到本机指定目录下的所有文件,为什么LISTBOX什么都没有显示阿?首先添加引用:using System.IO;然后在Page_Load中编写代码:string FilePath = "c:\\test";if(!Directory.Exists(FilePath))
   {
    Directory.CreateDirectory(FilePath);
   }
   if(!Directory.Exists(FilePath + "\\Abnormal"))
   {
    Directory.CreateDirectory(FilePath + "\\Abnormal");
   }   DirectoryInfo UnPostil = new DirectoryInfo(FilePath + "\\Abnormal");
   FileInfo[] ArrUnPostil = UnPostil.GetFiles();
   LB_Postil.Items.Clear();
   foreach (FileInfo FileName in ArrUnPostil)
   {
    if(FileName.Length > 0)
    {
     LB_Postil.Items.Add(FileName.Name);
    }
   }代码中的LB_Postil是一个LISTBOX服务器控件。

解决方案 »

  1.   

    LB_Postil.Items.Add(FileName.Name);
    lb_postil.items.add(new dataitem(filename.name));
      

  2.   

    lb_postil.items.add(new ListItem(filename.name));
      

  3.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    // Put user code to initialize the page here
    string FilePath = "D:\\test"; ArrayList values = new ArrayList(); if(!Directory.Exists(FilePath))
    {
    Directory.CreateDirectory(FilePath);
    }
    if(!Directory.Exists(FilePath + "\\Abnormal"))
    {
    Directory.CreateDirectory(FilePath + "\\Abnormal");
    } DirectoryInfo UnPostil = new DirectoryInfo(FilePath + "\\Abnormal");
    FileInfo[] ArrUnPostil = UnPostil.GetFiles();
    LB_Postil.Items.Clear();
    foreach (FileInfo FileName in ArrUnPostil)
    {
    if(FileName.Length > 0)
    {

    LB_Postil.Items.Add(new ListItem(FileName.Name));
    //LB_Postil.Items.Add(FileName.Name);
    }
    } }还是不行啊?为什么阿?怪了