Get files in a folder

后端 未结 2 1787
无人共我
无人共我 2020-12-25 14:08

In my MVC application I have the following paths;

  • /content/images/full
  • /content/images/thumbs

How would I, in my c# controller, get a l

2条回答
  •  太阳男子
    2020-12-25 14:15

    .NET 4.0 has got a more efficient method for this:

    Directory.EnumerateFiles(Server.MapPath("~/Content/images/thumbs"));
    

    You get an IEnumerable on which you can iterate on the view:

    @model IEnumerable
    
      @foreach (var fullPath in Model) { var fileName = Path.GetFileName(fullPath);
    • @fileName
    • }

提交回复
热议问题