0

我想将文件夹中的所有文件作为指向该文件的链接显示到面板。我已经这样做了。但它在流阅读器线上显示错误。说“无法将列表项转换为字符串”。请帮忙

      string[] filesPath = Directory.GetFiles(Server.MapPath("~/download_results/"));
    List<ListItem> files = new List<ListItem>();
    foreach (string path in filesPath)
    {
        files.Add(new ListItem(Path.GetFileName(path)));
    }

    ArrayList allFiles = new ArrayList();
    StreamReader reader = new StreamReader(files.ToString());
    string line = reader.ReadLine();
    while (line!= null)
    {

        if (Session["f_name"] != null)
        {
            allFiles = (ArrayList)Session["f_name"];
        }
        allFiles.Add(line);
        line = reader.ReadLine();

    }
    foreach (string fileName in allFiles)
    {
        Panel1.Controls.Add(new LiteralControl("<div>"));
        HyperLink hl = new HyperLink();
        hl.Text = fileName;
        hl.ID = fileName;
        hl.Target = "_blank";
        hl.NavigateUrl = "http://www.bbb.co/download_results/'"+fileName+"'";
        Panel1.Controls.Add(hl);
        Panel1.Controls.Add(new LiteralControl("</div>"));
    }
4

1 回答 1

0

这个怎么样:

string[] filesPath = Directory.GetFiles(Server.MapPath("~/download_results/"));

foreach (string fileName in filesPath)
        {
            string file = Path.GetFileName(fileName);
            Panel1.Controls.Add(new LiteralControl("<div>"));
            HyperLink hl = new HyperLink();
            hl.Text = file;
            hl.ID = file;
            hl.Target = "_blank";
            hl.NavigateUrl = "http://www.bbb.co/download_results/" + file;
            Panel1.Controls.Add(hl);
            Panel1.Controls.Add(new LiteralControl("</div>"));
        }

于 2013-09-25T05:05:17.687 回答