Load file content to DropDownList (VB) : File « File Directory « ASP.NET Tutorial






<%@ Page Language="VB" Debug="true" %>
<script runat="server">

Sub Page_Load (Sender As Object, E As EventArgs)

  Dim MyFileName as String
  Dim ObjectStreamReader as System.IO.StreamReader
  Dim FileLines as New ArrayList()

  MyFileName = Page.MapPath("Data.txt")

  Try
    ObjectStreamReader = new System.IO.StreamReader (MyFileName)
    While ObjectStreamReader.Peek() > -1
      FileLines.Add(ObjectStreamReader.ReadLine())
    End While
    FileLines.Sort()
    Label1.Text = "Select a title:"    
    DropDownList1.DataSource = FileLines
    DropDownList1.DataBind() 

  Catch ObjectError as Exception
      Label1.Text = ObjectError.Message
      DropDownList1.Visible = False
  Finally
    If Not ObjectStreamReader Is nothing Then
                  ObjectStreamReader.Close()
    End If
  End Try
End Sub
</script>
<html>
  <head>
  </head>
  <body>
    <form runat="server">
      <asp:Label id="Label1" runat="server"></asp:Label>
      <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>
    </form>
  </body>
</html>








10.1.File
10.1.1.Get file information (VB.net)
10.1.2.Opening a File (C#)
10.1.3.Opening a File (VB)
10.1.4.Delete a file (C#)
10.1.5.Delete a file (VB)
10.1.6.Creating a File (C#)
10.1.7.Creating a File (VB)
10.1.8.Load file content to DropDownList (C#)
10.1.9.Load file content to DropDownList (VB)
10.1.10.Rename File