Solved

ASPX directory listing

Posted on 2011-03-01
5
201 Views
Last Modified: 2012-05-11
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.
0
Comment
Question by:CaringIT
  • 2
  • 2
5 Comments
 

Author Comment

by:CaringIT
Comment Utility
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>  

0
 
LVL 18

Expert Comment

by:Ajay Sharma
Comment Utility
Add below attribute inside the HyperLinkColumn

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

and remove the DataFormatString property
0
 
LVL 8

Expert Comment

by:PagodNaUtak
Comment Utility
Change the line

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



0
 
LVL 8

Accepted Solution

by:
PagodNaUtak earned 500 total points
Comment Utility
Typo... It should be:

Change the line

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

Expert Comment

by:Ajay Sharma
Comment Utility
@CaringIT

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

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now