One day i created many aspx files in one directory, then I wanted to browse those files without going and clicking each one of them, I decided to write small function to create a hyperlink for each file. I thought someone else might benefit from the code, here it is:
strDir = "~/directoryname/"<br>
<br>
Private Sub createHyperlinks(ByVal strDir As String)
Dim i As Integer = 1
For Each file As String In Directory.GetFiles(Server.MapPath(strDir))
If Path.GetFileName(file).EndsWith(".aspx") Then
Dim lnk As New HyperLink
PlaceHolder1.Controls.Add(GetLiteral("<br />"))
lnk.ID = "lnk" & i.ToString()
lnk.NavigateUrl = strDir & Path.GetFileName(file)
lnk.Text = Mid(Path.GetFileName(file), 1, (Path.GetFileName(file)).IndexOf("."))
PlaceHolder1.Controls.Add(lnk)
i += 1
End If
Next
End Sub
Private Function GetLiteral(ByVal text As String) As Literal
Dim rv As Literal
rv = New Literal
rv.Text = text
Return rv
End Function
And finally here is the html:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
</div>
</form>
</body>
</html>
Hope you like it, thank you.