I am using the following code to display the contents of a directory on the server. I want the datagrid to allow download of each of the files. The datagrid is successfully populating the table however the hyperlinks go to the root of the site instead of the directory of the server.mappath and I don't know why. Can anyone please provide some guidance as to what I am doing wrong?
I hope that helps.
Regards,
Mark
Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
Code:
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<html>
<head>
<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
Dim dirInfo As New DirectoryInfo(Server.MapPath("Uploads"))
articleList.DataSource = dirInfo.GetFiles("*.*")
articleList.DataBind()
End Sub
</script>
</head>
<body>
<div Align="center">
<img src="Images/SN_LOGO_3.gif" />
</div>
<div id="navigation">
<center>
<hr /><hr /><br />
<a href="FileDownload.aspx"><img src="Images/download.jpg" border="0" /></a>
<a href="FileUpload.aspx"><img src="Images/upload.jpg" border="0" /></a>
</center>
<br /><hr />
</div>
<hr />
<div id="downloadarea">
<div id="dlHeader" style="font-size: xx-large">Available Downloads</div>
<asp:DataGrid runat="server" id="articleList" Font-Name="Verdana"
AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#0099ff"
HeaderStyle-BackColor="#0099ff" HeaderStyle-ForeColor="White"
HeaderStyle-Font-Size="15pt" HeaderStyle-Font-Bold="True">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name"
HeaderText="File Name" />
<asp:BoundColumn DataField="LastWriteTime" HeaderText="File Date"
ItemStyle-HorizontalAlign="Center" DataFormatString="{0:d}" />
<asp:BoundColumn DataField="Length" HeaderText="File Size"
ItemStyle-HorizontalAlign="Right"
DataFormatString="{0:#,### bytes}" />
</Columns>
</asp:DataGrid>
</div>
</body>
</html>
I hope that helps.
Regards,
Mark
Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.