Link to home
Start Free TrialLog in
Avatar of CaringIT
CaringITFlag for United Kingdom of Great Britain and Northern Ireland

asked on

ASPX directory listing

I've got the following script which lists the files in a directory and creates a link to them, but they are located in another folder.  When clicking on the link, it assumes the file is in a different folder.

How do I modify this to reflect the files being in another folder from the script?

Many thanks.
Avatar of CaringIT
CaringIT
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Better add the script here:

 <%@ Import Namespace="System.IO" %>
<script language="VB" runat="server">
  Sub Page_Load(sender as Object, e as EventArgs)
    Dim dirInfo as New DirectoryInfo(Server.MapPath("Resources/alerts/"))
   
    articleList.DataSource = dirInfo.GetFiles("*.pdf")
    articleList.DataBind()
  End Sub
</script>

<asp:DataGrid runat="server" id="articleList" Font-Name="Verdana"
      AutoGenerateColumns="False" AlternatingItemStyle-BackColor="#eeeeee"
      HeaderStyle-BackColor="Navy" HeaderStyle-ForeColor="White"
      HeaderStyle-Font-Size="10pt" HeaderStyle-Font-Bold="True">
  <Columns>
    <asp:HyperLinkColumn DataNavigateUrlField="Name" DataTextField="Name" HeaderText="File Name" />
    <asp:BoundColumn DataField="LastWriteTime" HeaderText="Date Saved"
        ItemStyle-HorizontalAlign="Center" DataFormatString="{0:d}" />
  </Columns>
</asp:DataGrid>  

Add below attribute inside the HyperLinkColumn

datanavigateurlformatstring="~\Resources\alerts\{0:d}"

and remove the DataFormatString property
Change the line

Dim dirInfo as New DirectoryInfo(Server.MapPath("Resources/alerts/"))
to
Dim dirInfo as New DirectoryInfo(Server.MapPath("Resources/alerts/"))



ASKER CERTIFIED SOLUTION
Avatar of PagodNaUtak
PagodNaUtak
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
@CaringIT

Is your problem got solved? If yes then please close the question.