questo è un altro modo per ordinare il vettore. Fa uso di un vettore che contiene le chiavi di ordinamento

codice:
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    /*--------------------------------------------------------------
    scrivo 20 files in c:\tmp\tmp, da 1.txt a 20.txt
    ---------------------------------------------------------------*/
    protected void Button1_Click(object sender, EventArgs e)
    {
        for (int i = 1; i <= 20; i++)
        {
            string s = i.ToString() + ".txt";
            string f = Path.Combine("c:\\tmp\\tmp", s);
            //libreria.ModuloWeb.PrintLn(f);
            StreamWriter sw = File.CreateText(f);
            sw.Close();
        }
    }

    
    /*------------------------------------------------------------
     * lista i files ordinandoli per nome (ordine numerico)
     * 
     * ----------------------------------------------------------*/
    protected void Button2_Click(object sender, EventArgs e)
    {
        string path = "c:\\tmp\\tmp";
        //vettore dei files
        string[] fs = Directory.GetFiles(path);
        
        //vettore ausiliario per l'ordinamento
        int[] va = new int[fs.Length];
        for (int i = 0; i < va.Length; i++)
            va[i] = int.Parse(Path.GetFileNameWithoutExtension(fs[i]));
        Array.Sort(va, fs);
        
        StringBuilder sb = new StringBuilder();
        sb.Append("<Table>");
        foreach (string f in fs)
        {
            sb.Append("<tr><td>" + f + "</td></tr>");
        }
        sb.Append("</table>");
        this.form1.Controls.Add(new LiteralControl(sb.ToString()));
    }

    
    
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Pagina senza titolo</title>
    <link href="../../stili/Styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="crea i files" /><asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Text="Leggi files" /></div>
    </form>
</body>
</html>