[英]ASP.NET how to get file name in specific folder on server
I have this website which I am coding in ASP.NET - C#. 我有这个网站,我在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.
现在每个图像框都有自己的文件夹,在任何时候,该文件夹中只能有一个文件,即.JPG文件。
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. 我想要做的就是在文件夹img / home / 1 / ....中获取文件名,然后我可以将图片框的源设置为该名称。
How can I get that filename in that specific folder? 如何在该特定文件夹中获取该文件名?
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 然后只需使用filePaths [0]索引中的文件名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.