简体   繁体   中英

How to display files inside subdirectory

I am having difficulty understanding on how to go about displaying images inside sub directories.

Currently I have the following code which goes about displaying the image files within these subdirectories

Code Behind

protected void Page_Load(object sender, EventArgs e)
{
  if (!IsPostBack)
  {
    List<string> files = new List<string> (Directory.GetFiles(Server.MapPath("/Screenshots/"), "*.png", SearchOption.AllDirectories));

    files = files.Select(s => s.Replace(@"D:\wwwroot\blah\blah", "")).ToList();

    rptDirectory.DataSource = files;
    rptDirectory.DataBind();        
  }
}  

Front end

<asp:Repeater ID="rptDirectory" runat="server">
<HeaderTemplate>            
  <h2>Results</h2>
  <br />
  <div style="display: inline;">
</HeaderTemplate>
<ItemTemplate>
  <ul>
      <li> <asp:HyperLink ID="hplFolder" runat="server" NavigateUrl="<%# Container.DataItem%>" Text="<%# Container.DataItem %>" /></li>
  </ul>         
</ItemTemplate>    
</asp:Repeater>  

The above works fine and I am able to display all the images on one page.

However, I want to first display their parent folders first as a hyperlink/link where user then clicks on the link and it take them to another page where all the images for that parent folder will be displayed

Currently the folder structure is as follows

  • Screenshot (Parent)
    • Folder1 (Child)
      • Another Folder (Siblings)
        • Images

So basically want to Display the Folder 1 name as the hyperlink and then when I click on the folder it takes me to another page where the images are displayed.

Should I use another asp panel to display the images?

Hope I haven't confused what I have said above?

Thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM