【发布时间】:2017-10-30 07:40:05
【问题描述】:
我是 C# 编程语言的新手。任何人都可以帮助我如何从 folder>folder>folder>image 的多个文件夹中检索图像。下面是我已经尝试过的代码,但它只在 folder>image 时检索图像。我已经尝试过这样的string baseFolder = @"\\\\egmnas01\\hr\\photo\\~";但仍然无法正常工作。请有人帮助我。谢谢。
string baseFolder = @"\\\\egmnas01\\hr\\photo\\";
string[] employeeFolders = Directory.GetDirectories(baseFolder);
string imgName = textBoxEmplNo.Text + ".jpg";
bool fileFound = false;
foreach (var folderName in employeeFolders)
{
var path = Path.Combine(folderName, imgName);
if (File.Exists(path))
{
pictureBox1.Visible = true;
pictureBox1.Image = Image.FromFile(path);
fileFound = true;
}
}
if (!fileFound)
{
pictureBox1.Visible = true;
pictureBox1.Image = Image.FromFile(@"C:\Users\jun\Desktop\images\photo\No-image-found.jpg");
}
【问题讨论】:
-
您是否想在子目录树中查找名称与您提供的文件名匹配的任何文件?如果您不知道子目录,您可能需要这样的东西来查找匹配的文件:
System.IO.Directory.GetFiles(@"c:\test\", "\\*.jpg", System.IO.SearchOption.AllDirectories); -
@john 该代码替换此代码
string baseFolder = @"\\\\egmnas01\\hr\\photo\\";?因为我已经尝试过了,但还是不行。
标签: c# visual-studio-2013 windows-forms-designer