I have an application where you can insert attachments and then download them. But I've done it in a way that for every file format I want to insert as an attachment, I enter a For Each
this way
Private Sub grdAnexo_ItemCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles grdAnexo.ItemCommand
Dim idLote As Integer = Integer.Parse(e.CommandArgument)
Dim diretorio As New DirectoryInfo(Server.MapPath("Lote_Garantia\"))
Dim arquivo As FileInfo
For Each item As FileInfo In diretorio.GetFiles("Lote_" + idLote.ToString + ".xls")
arquivo = item
Next
For Each item As FileInfo In diretorio.GetFiles("Lote_" + idLote.ToString + ".xlsx")
arquivo = item
Next
For Each item As FileInfo In diretorio.GetFiles("Lote_" + idLote.ToString + ".pdf")
arquivo = item
Next
For Each item As FileInfo In diretorio.GetFiles("Lote_" + idLote.ToString + ".xml")
arquivo = item
Next
For Each item As FileInfo In diretorio.GetFiles("Lote_" + idLote.ToString + ".jpg")
arquivo = item
Next
For Each item As FileInfo In diretorio.GetFiles("Lote_" + idLote.ToString + ".jpeg")
arquivo = item
Next
For Each item As FileInfo In diretorio.GetFiles("Lote_" + idLote.ToString + ".bmp")
arquivo = item
Next
For Each item As FileInfo In diretorio.GetFiles("Lote_" + idLote.ToString + ".gif")
arquivo = item
Next
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Disposition", String.Format("attachment;filename=""{0}""", arquivo.Name))
Response.AddHeader("Content-Length", arquivo.Length.ToString())
Response.WriteFile(arquivo.FullName)
Response.End()
End Sub
My doubt is, a means of having the attachment accept any file format without having to create a new For Each
for each one.
It's possible ? Or do I have to keep adding for
to each format?