List the contents of a folder and link to each file
Iterating the contents of a folder is straightforward using classes from System.IO, and listing them as links to the actual file just requires a bit of html added to each file name.
[C#]
using System.IO;
using System.Text;
DirectoryInfo dir;
StringBuilder sb = new StringBuilder();
FileInfo[] files;
dir = new DirectoryInfo(Server.MapPath("."));
files = dir.GetFiles();
foreach (FileInfo f in files)
{
sb.Append("<a href=\"" + f.Name.ToString() + "\">");
sb.Append(f.Name.ToString() + "</a><br />");
}
Literal1.Text = sb.ToString();
[VB]
Imports System.Text
Imports System.IO
Dim dir As DirectoryInfo
Dim sb As StringBuilder = New StringBuilder()
Dim files() As FileInfo 'array of fileinfo objects
dir = New DirectoryInfo(Server.MapPath("."))
files = dir.GetFiles()
For Each f As FileInfo In files
sb.Append("lt;a href=""" + f.Name.ToString() + """>")
sb.Append(f.Name.ToString() + "lt;/a>lt;br />")
Next
Literal1.Text = sb.ToString()
Currently rated 3.00 by 2 people
Rate Now!
Date Posted:
10 August 2007 21:33
Last Updated:
Posted by:
Mikesdotnetting
Total Views to date:
1669
Printer Friendly Version


