Sahil Tiwari
Sahil Tiwari

Reputation: 169

How do I access Images folder in the controller in the current development server?

My development server is called the WebApp which has the following folders as shown in the image. I want to write a method/function to access the 'Images' folder inside the controller while the application is running

enter image description here

Upvotes: 2

Views: 1287

Answers (1)

Icculus018
Icculus018

Reputation: 1066

You need to get the path to the folder and then can access each file in the folder. Try this:

string path = Server.MapPath("~/Images/");
DirectoryInfo dirInfo = new DirectoryInfo(path);
FileInfo[] files = dirInfo.GetFiles();

foreach(FileInfo file in files)
{
    string fileName = file.Name;
}

Upvotes: 4

Related Questions