2
I need to find a file automatically without opening 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 this final part will never repeat. I even made this code here below but I was not successful, because I can get all the files from this directory but I am not able to identify the file that ends 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;
}