-1

I have a FileInfo object that receives all images from a directory:-

string Path = HttpContext.Server.MapPath("~/Content/TempImages/");
DirectoryInfo directory = new DirectoryInfo(Path);
FileInfo[] files = directory.GetFiles();

This works fine and gets all the images from the directory. However, I only want to get specific images from the directory which I have in a list (ImagesToShow):-

string Path = HttpContext.Server.MapPath("~/Content/TempDocs/");
foreach (var image in ImagesToShow)
{
  //How do I add all image.imageName to the FileInfo[] object?
}
Sherry8212
  • 67
  • 1
  • 11

1 Answers1

0

Got it working with a List<>

      var AllDocs = //List of image names

      string path = HttpContext.Server.MapPath("~/Content/TempImages/");
      List<FileInfo> filelist = new List<FileInfo>();
      foreach (var item in AllDocs)
      {
         filelist.Add(new FileInfo(path + item.ImageName));
      }

Then convert to array if needed

      FileInfo[] newfiles = filelist.ToArray(); 
Sherry8212
  • 67
  • 1
  • 11