We start with creating a DirectoryInfo object and the directory whose files has been to displayed is passed to the constructor.
System.IO.FileInfo[] fiArr=di.GetFiles(); |
Next, we call the GetFiles() method of the DirectoryInfo object. It returns a array of FileInfo objects.
foreach (System.IO.FileInfo fi in fiArr) { Response.Write("<a href='"+fi.Name+"'>"+fi.Name+ "<br>") ; } |
Last, for each FileInfo object, we construct a anchor tag.
Alternatively, We can create Hyperlink objects,set the Text and NavigateURL properties and add it to the page.
HyperLink hl=new HyperLink(); hl.NavigateUrl=fi.Name; hl.Text=fi.Name; Page.Controls.Add(hl); |
VB.NET Code:
Dim di As New System.IO.DirectoryInfo("C:\Inetpub\wwwroot\WebApplication2\") Dim fiArr As System.IO.FileInfo() = di.GetFiles() Dim fi As System.IO.FileInfo
For Each fi In fiArr Response.Write("<a href='" + fi.Name + "'>" + fi.Name + "<br>") Next fi
|
Send your comments to rajiv.raj@wipro.com