I need to find a file automatically without having to open a check box for the user to select the file. Where I already have the directory of the folder where this file will stay and I also know the part of the final name of this file, and that final part will never repeat itself. I got to do this code here but I did not succeed, because I can get all the files in this directory but I can not identify the file ending with the given name:
private string localizarArquivo()
{
DirectoryInfo diretorio = new DirectoryInfo(NFe.DiretorioLog); // C:\Users\WIN\Documents\Visual Studio 2015\Projects\Demo NFe - VS2012 - C#\bin\Debug\Log\
string chave = edtIdNFe.Text.Trim();
string ParteFinal = chave + "-env-sinc-ret.xml"; // 26151003703802000156550100000004521376169520-env-sinc-ret.xml
string ArquivoLog = String.Empty; // Deverá ser: diretorio + ??????? + ParteFinal
foreach (FileInfo f in diretorio.GetFiles())
{
if (f.Extension.ToLower() == ParteFinal)
ArquivoLog = f.ToString();
}
if (File.Exists(ArquivoLog))
return ArquivoLog;
return null;
}