如何将图像文件从本地驱动器检索到文件名以参数开头的 Crystal 报表



我想从本地驱动器获取图像文件。文件名以参数值(例如数字 x)开头。所以我需要获取以名称"x"开头的图像。
有人可以帮助我吗?

你可以试试这个:

static void Main(string[] args)
    {
        string parameter = "te"; // Replace with your parameter
        string regexp = string.Format(@"{0}.*.png", parameter); // Change the image format as required. eg. .png to .jpg
        DirectoryInfo di = new DirectoryInfo(@"C:FilePath");
        foreach (var fname in di.GetFiles())
        {
            if (Regex.IsMatch(fname.Name, regexp) )
            {
                Console.WriteLine(fname.Name);
                // Do your processing here with the file.
            }
        }
        Console.ReadLine();
    }

基本上,我正在浏览目录,枚举文件并将文件名与正则表达式匹配。

注意,我在这里使用了正则表达式,如果只想匹配文件名的开头,也可以使用以下内容:

if (fname.Name.StartsWith(parameter) && fname.Name.EndsWith(".png"))

希望这有帮助。

最新更新