Naturalmente il metodo suggerito da Gianni83 è quello principe.
Ma se ti vuoi divertire prova anche questo
pagina
codice:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="a.aspx.vb" Inherits="CorsoApogeo_LINQ_a" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Button ID="Button2" runat="server" Text="Button" />
<asp:Button ID="Button3" runat="server" Text="Button" />
<hr />
<asp:DropDownList ID="DropDownList1" runat="server" EnableViewState="False">
</asp:DropDownList>
</form>
</body>
</html>
codice
codice:
Option Strict On
Partial Class CorsoApogeo_LINQ_a
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim imgs As String() = Directory.GetFiles("C:\dati\ProveNikon\images")
Me.DropDownList1.DataSource = imgs
Me.DropDownList1.DataBind()
End Sub
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim result = From f In Directory.GetFiles("C:\dati\ProveNikon\images") _
Where Path.GetExtension(f) = ".jpg" Select f
Me.DropDownList1.DataSource = result
Me.DropDownList1.DataBind()
End Sub
Protected Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
'tutti i file di C:\dati\ProveNikon\images
'con estensione jpg
'di dimensione < 40000 byte
'ordinati per nome
'option ha text:= nome file, value:= percorso completo
Dim di As New DirectoryInfo("C:\dati\ProveNikon\images")
Dim result = From fi In di.GetFiles("*.jpg") _
Where fi.Length < 40000 _
Order By fi.Name _
Select New With {.Name = fi.Name, .FullName = fi.FullName}
Me.DropDownList1.DataSource = result
Me.DropDownList1.DataTextField = "Name"
Me.DropDownList1.DataValueField = "FullName"
Me.DropDownList1.DataBind()
End Sub
End Class