C# 如何将图像文件从本地驱动器检索到文件名以参数开头的Crystal Reports?
我想从本地驱动器获取一个映像文件。文件名以一个参数值(比如数字x)开头。因此,我需要获取以名称“x”开头的图像。C# 如何将图像文件从本地驱动器检索到文件名以参数开头的Crystal Reports?,c#,crystal-reports,C#,Crystal Reports,我想从本地驱动器获取一个映像文件。文件名以一个参数值(比如数字x)开头。因此,我需要获取以名称“x”开头的图像。 有人能帮我吗?你可以试试这个: static void Main(string[] args) { string parameter = "te"; // Replace with your parameter string regexp = string.Format(@"{0}.*\.png", parameter); // Chang
有人能帮我吗?你可以试试这个:
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"))
希望这有帮助