2
I have a screen where I list files from a certain folder. I have a search bar that uses the same method to find files, but I can’t list by approximation. Example:
I have this file Papel_timbrado.docx
.
If I search "Paper" I find the file, but if I search "Letterhead" my search returns blank. there is some way to find by approximation the files?
I’m using the class System.IO
to find the files (GetFiles
)
public void PopulaLista(string arquivo, string extensao)
{
string resposta = "<table class=\"table table-striped table-bordered table_qr\" id=\"sample_1\" runat=\"server\">";
DirectoryInfo diretorio = new DirectoryInfo(objUtils.Diretorio("upload/pastamateriais/"));
if (string.IsNullOrWhiteSpace(arquivo) == true) { arquivo = "*"; }
FileInfo[] Arquivos = diretorio.GetFiles(arquivo + extensao);
resposta += " <thead>";
resposta += " <tr>";
resposta += " <th>Nome do Arquivo</th>";
resposta += " <th>Tipo</th>";
resposta += " <th>Tamanho</th>";
resposta += " <th style=\"width:70px;\">Ações</th>";
resposta += " </tr>";
resposta += " </thead>";
resposta += " <tbody>";
TextInfo myTI = new CultureInfo("en-US", false).TextInfo;
foreach (FileInfo fileinfos in Arquivos)
{
if (fileinfos.Name != "Thumbs.db")
{
resposta += " <tr>";
resposta += " <td>" + myTI.ToTitleCase(fileinfos.Name.Replace(fileinfos.Extension, "").Replace("_", " ").Replace("-"," ")) + "</td>";
resposta += " <td><img alt='" + fileinfos.Extension + "' src='images/icon-" + fileinfos.Extension.Replace(".", "") + ".png' /></td>";
resposta += " <td>" + Convert.ToDecimal(fileinfos.Length / 1024) + " KB</td>";
resposta += " <td><a href=upload/pastamateriais/" + fileinfos.Name + " class=\"img_edit\" download><img src=\"images/download.png\" /></a><a id='" + fileinfos.Name + "' href=\"javascript:void(0)\" onclick='apagar(this.id);' class=\"img_del\"><img src=\"images/lixo.png\" /></a></td>";
resposta += " </tr>";
}
}
resposta += " </tbody>";
resposta += "</table>";
if (Request["acao"] == "Pesquisar")
{
Response.Write(resposta);
}
else
{
divLista.InnerHtml = resposta;
}
}
Could you please post the code that filters these files by name? from what you have said, the code must be with Startswith(), if you change to a Contains() must resolve.
– PauloHDSousa
It would be interesting to see the code you are using. You are using wildcards?
– André Ribeiro