Reputation: 2478
I have this website which I am coding in ASP.NET - C#.
My problem is that I have image boxes, but the user can upload images with any name. Now each image box has its own folder, and at any point, there can be only one file in that folder, which is a .JPG file.
the path looks like this:
Server.MapPath("img/home/1/here can be any jpg file with any name eg. whateverPic.jpg")
So, when uploading the file, the name can change at any time... then the problem comes when I want to display the image in the picture box.
All I want to do is to get the file name in folder img/home/1/.... and then I can just set the source of the picturebox to that name.
How can I get that filename in that specific folder?
Upvotes: 1
Views: 8741
Reputation: 2762
you can use this to get a list of files in the directory
string[] filePaths = Directory.GetFiles(@"c:\MyDir\");
then just use the file name in the filePaths[0] index
Upvotes: 3