【问题标题】:how to display files of a folder in listbox by browsing the folder using asp.net如何通过使用asp.net浏览文件夹在列表框中显示文件夹的文件
【发布时间】:2016-02-25 07:08:18
【问题描述】:
string path = TextBox1.Text;
DirectoryInfo dtr = new DirectoryInfo(path);
if (dtr.Exists)
{
    FileInfo[] files = dtr.GetFiles("*.txt");
    foreach (FileInfo file in files)
    {
        ListBox1.Items.Add(file.Name);
    }
    Label1.Text = "entered to listbox";
}
else
{
    Label1.Text = "directory doesnt exit";
}

我正在使用 asp.net, 我有一个文本框、一个按钮和一个列表框, 我正在复制文本框中文件夹的路径,然后单击按钮,它会显示列表框中的所有文本文件..... 但是,我不想将文件夹路径复制到文本框,而是我想在按钮单击时浏览文件夹,它将在文本框中显示路径,在另一个按钮上单击它将显示该特定文件夹内的文件

【问题讨论】:

    标签: asp.net


    【解决方案1】:

    替换

    ListBox1.Items.Add(file.Name);
    

    ListBox1.Items.Add(file.Name.Substring(file.Name.LastIndexOf('\\')));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多