文件夹中获取文件 [英] Get files in a folder

查看:202
本文介绍了文件夹中获取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的MVC应用程序,我有以下路径;


  • /内容/图像/全

  • /内容/图像/拇指

我怎么会在我的C#的控制器,让我的拇指内的所有文件的列表文件夹?

修改

时仍然使用Server.Mappath最好的方式?

我有这个现在 DirectoryInfo的DI =新DirectoryInfo的(使用Server.Mappath(/内容/图像/拇指)); ,但觉得这是不正确的做法

有没有在MVC最佳实践为这个或以上仍然正确?


解决方案

  Directory.GetFiles(/内容/图像/拇指)

这将获得目录中的所有文件放到一个字符串数组。

In my MVC application I have the following paths;

  • /content/images/full
  • /content/images/thumbs

How would I, in my c# controller, get a list of all the files within my thumbs folder?

Edit

Is Server.MapPath still the best way?

I have this now DirectoryInfo di = new DirectoryInfo(Server.MapPath("/content/images/thumbs") ); but feel it's not the right way.

is there a best practice in MVC for this or is the above still correct?

解决方案

Directory.GetFiles("/content/images/thumbs")

That will get all the files in a directory into a string array.

这篇关于文件夹中获取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆