简体   繁体   English

ASP.NET如何在服务器上的特定文件夹中获取文件名

[英]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.

相关问题 asp.net获取特定文件夹内文件的文件名 - asp.net get filename of a file inside the specific folder 如何使用asp.net从文件夹中删除特定文件 - How to delete a specific file from folder using asp.net ASP.Net MVC允许显式路由到文件夹名称中带有点的特定文件 - ASP.Net MVC Allows Explicit Routing to Specific File Having Dot in the Folder Name 如何从服务器获取JSON文件? (ASP.NET) - How to get JSON file from server? (ASP.NET) 指定asp.net核心静态文件夹的默认文件名 - Specifying default file name for asp.net core static folder 如何使用c#在asp.net中使用MemoryStream将文本/文档文件保存到特定文件夹? - How to save a Text/document file to specific folder using MemoryStream in asp.net using c#? ASP.NET Core(Razor 页面) - 如何在(客户端的)特定文件夹中下载文件 - ASP.NET Core (Razor page) - how to download a file in a specific folder (of the client) 如何删除所有文件而不删除Asp.net解决方案资源管理器文件夹中的特定文件? - How to delete all files without deleting a specific file in Asp.net solution explorer's folder? asp.net在其他服务器中创建文件夹和文件 - asp.net create folder and file in other server 如何使用ASP.NET为文件夹设置特定的404? - How to have a specific 404 for a folder using ASP.NET?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM