Home » .NET 4.0 » Read the content of the folder – VB.NET

Read the content of the folder – VB.NET

<%@ Page Language="VB" %>

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.IO.FileInfo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<style type="text/css">
ul { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 12px; 
     font-style: normal; line-height: 25px; font-variant: normal; 
     color: #0C4F93; text-indent: 5px; 
     list-style-position: outside; list-style-type: square;

<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        ' make a reference to a directory
        Dim DirPath As New IO.DirectoryInfo("C:\\My_Folder")
        Dim FCollect As IO.FileInfo() = DirPath.GetFiles()
        Dim FInfo As IO.FileInfo
        'list the names of all files in the specified directory
        For Each FInfo In FCollect
            Dim LnItem = New ListItem(FInfo.ToString, 
             "http://my_webstie/My_Folder" & FInfo.ToString)
            BulletedList1.Target = "_blank"
    End Sub


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>List directory
<link href="Styles/Site.css" rel="stylesheet" type="text/css" />
<div class="page">
<div class="header">
<div class="nav_pos" >
<div class="nav_format">
<% Response.Write(MonthName(DateTime.Now.Month) & " " & DateTime.Now.Day &_
     ", " & DateTime.Now.Year) %> 

<div id='MenuPos' style="position:relative;">
<% Response.WriteFile("site_menu/top_menu.asp")%>
<legend>5500 Forms and Summary Annual Reports for 2011
<form id="form1" runat="server">
<div style="padding-left: 20px;">
<asp:bulletedlist ID="BulletedList1" runat="server" 
DisplayMode="HyperLink" BulletStyle="NotSet" >
<div class="footer">Copyright © < %= Date.Today.Year.ToString() %>
 - My Website Name® - All Rights Reserved.