ASP.Net/File Directory/Directory — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 15:30, 26 мая 2010

Get all exe files (C#)

<%@ Page Language="C#" %>
<%@ import Namespace="System.IO" %>
<script runat="server">
    private void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            String[] FileCollection;
            FileInfo FileInfo;
            int i;
        
            FileCollection = Directory.GetFiles(@"C:\WINNT","*.exe");
        
            for (i=0; i < FileCollection.Length; i++)
            {
                FileInfo = new FileInfo(FileCollection[i]);
                FileListBox.Items.Add(new ListItem(FileInfo.Name.ToString()));
            }
        }
    }
</script>
<html>
  <head>
  </head>
  <body>
    <form runat="server">
      EXE Files in Folder C:\WINNT:
      <asp:ListBox id="FileListBox" Runat="Server" />
    </form>
  </body>
</html>



Get all exe files (VB)

<%@ Page Language="VB" %>
<%@ import Namespace="System.IO" %>
<script runat="server">
  Sub Page_Load(Sender As Object, E As EventArgs)
    If Not IsPostBack Then
      Dim FileCollection As String()
      Dim myFileInfo As FileInfo
      Dim i as integer
      
      FileCollection = Directory.GetFiles("C:\WINNT","*.exe")
      For i = 0 To FileCollection.Length - 1
        myFileInfo = New FileInfo(FileCollection(i))
        FileListBox.Items.Add(new ListItem(myFileInfo.Name.ToString()))
      Next
    End If
  End Sub
</script>
<html>
  <head>
  </head>
  <body>
<form runat="server">
  EXE Files in Folder C:\WINNT:
  <asp:ListBox id="FileListBox" Runat="Server" />
</form>
  </body>
</html>