Link to home
Start Free TrialLog in
Avatar of Carla Romere
Carla RomereFlag for United States of America

asked on

Using DataNavigateUrlFormatString to reference another directory

I have a page that displays all the files in a specific directory.

    public void Page_Load(object sender, EventArgs e)
        DirectoryInfo dirInfo = new DirectoryInfo(Server.MapPath("../data"));
        articleList.DataSource = dirInfo.GetFiles("*.*");

This part works great. However, when I click on one of the files, I can't get it to see the directory where the files are located. Here is the display code:

    <asp:HyperLinkColumn DataNavigateUrlField="Name" DataNavigateUrlFormatString="../data/[Name]"  DataTextField="Name"
           HeaderText="File Name" />

When I click on the file, the hyperlink shows the correct folder now, but I can't get the file name to display. The file name needs to be in the code above where I have [Name]. The name of the field that has the file name in it is simply "Name". How can I get the hyperlink URL to show the correct folder AND the correct file name?
Avatar of Jeeva Subburaj
Jeeva Subburaj
Flag of United States of America image

try this

<asp:HyperLinkColumn NavigateUrl='<%# "../data/" + DataBinder.Eval(Container, "Name")%>'    >

Avatar of jandromeda
Flag of Sri Lanka image

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


Perfect! Thank you so much.