获取Visual Studio Project解决方案的images文件夹中的所有文件的列表

时间:2021-07-28 22:48:08

I want to loop over all the files in the images folder of my solution.

我想循环遍历解决方案的images文件夹中的所有文件。

HtmlGenericControl iframe;
foreach (var item in Directory.GetFiles(ResolveClientUrl("~/Images")))
{
   //images will be loaded dynamically into iframes here.
}

I also tried with this AppDomain.CurrentDomain.BaseDirectory but i am not able to do it.

我也试过这个AppDomain.CurrentDomain.BaseDirectory,但我无法做到。

2 个解决方案

#1


0  

You did not write exactly, what the problem is. I can only GUESS that you do not receive any file, but no Exception, either. If that is the case:

你没准确写,问题是什么。我只能GUESS你没有收到任何文件,但也没有Exception。如果是这种情况:

Did you change the files property to "Copy always" or "copy when newer"?

您是否将文件属性更改为“始终复制”或“更新时复制”?

#2


0  

 String virtualPath = Server.MapPath("~");
DirectoryInfo directoryInfo = new DirectoryInfo(virtualPath);
DirectoryInfo[] subFolders = directoryInfo.GetDirectories();

// This will give you all the folders

//这将为您提供所有文件夹

foreach (DirectoryInfo subFolder in subFolders)
{
    if(subFolder=="images")
      {
        FileInfo[] fileInfo = subFolder.GetFiles();
      }
} 

Try this.. This will work

试试这个......这样可行

#1


0  

You did not write exactly, what the problem is. I can only GUESS that you do not receive any file, but no Exception, either. If that is the case:

你没准确写,问题是什么。我只能GUESS你没有收到任何文件,但也没有Exception。如果是这种情况:

Did you change the files property to "Copy always" or "copy when newer"?

您是否将文件属性更改为“始终复制”或“更新时复制”?

#2


0  

 String virtualPath = Server.MapPath("~");
DirectoryInfo directoryInfo = new DirectoryInfo(virtualPath);
DirectoryInfo[] subFolders = directoryInfo.GetDirectories();

// This will give you all the folders

//这将为您提供所有文件夹

foreach (DirectoryInfo subFolder in subFolders)
{
    if(subFolder=="images")
      {
        FileInfo[] fileInfo = subFolder.GetFiles();
      }
} 

Try this.. This will work

试试这个......这样可行