Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directory.GetFiles() returns full path

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??

like image 974
Spirals Whirls Avatar asked Feb 14 '26 08:02

Spirals Whirls


1 Answers

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.

like image 68
Oded Avatar answered Feb 16 '26 21:02

Oded



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!