I want to return the files that are images, inside a particular directory. I want to create the image path like this
string[] ImageNames = Directory.GetFiles(path);
string tds="";
for (int i = 0; i < ImageNames.Length; i++)
{
tds += "<tr> <td> <img href=/Articles/ArticleImageStore/'" + ImageNames[i] + "' width='64' height='64'></img></tr> </td>";
}
but it returns the physical path of the file on the disk. How should I do this??
You can use Path.GetFileName:
string[] ImageNames = Directory.GetFiles(path)
.Select(p => Path.GetFileName(p)).ToArray();
This will produce a list with only the names of the files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With