Phantom_strike Phantom_strike - 1 year ago 69 Question

Search multiple file names from the database

My problem is that I'm trying to get all file names from the data base, but this only works if I write specifically the file names, for example, in my db I have a column named "File" and it's only the name of the file without any extension so I call the variable "file_name" and add the extension but doesn't seem to work...

Here is the table:

Id | Court | File | Email
1 | COURT NUMBER 1 | DocumentA |
2 | COURT NUMBER 1 | DocumentB |
3 | COURT NUMBER 1 | DocumentC |
4 | COURT NUMBER 1 | DocumentD |

And here is the code:

If (Court.ToUpper.Trim = "COURT NUMER 1") Then
Dim di As DirectoryInfo = New DirectoryInfo("\\\SisInt\Court\Agreements\J102016SEM" & semester)

For Each fi In di.GetFiles(file_name.Trim + "docx")

If fi.Extension.ToUpper = ".DOC" Or fi.Extension.ToUpper = ".DOCX" Then
NameList.Add((fi.Name.Substring(0, fi.Name.Length - fi.Extension.Length)))

End If
End If

But this only works if I write exactly the name of one file with the extension (doesn't work if I put more than one file name)

For Each fi In di.GetFiles("DocumentA.docx")

So, any idea how to call all the file names from the datebase at once?

Answer Source

Change your search pattern to this:

di.GetFiles(file_name.Trim + ".doc*")

And you can get the file name without the extension in an easier way:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download