I have an aspx page that I am displaying image from codehind c#. Every item has it's own directory with images inside if there were any uploaded. It works fine except if the directory doesn't exist for a certain item, I get a return error "Could not find part of the path.... In some cases the directory will not exist because there are no images assigned to the item. What should I include in my code to ignore this if there is no directory for the item?
Below is the code used to display the images:
string[] filePaths = Directory.GetFiles(Server.MapPath("/Test/Files/Item" + ItemNumber + "/"));
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
string fileName = Path.GetFileName(filePath);
files.Add(new ListItem(fileName, "/Test/Files/Item" + ItemNumber + "/" + fileName));
}