Solved

ASPX directory listing

Posted on 2011-03-01
5
203 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
ID: 35005358
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
ID: 35005425
Add below attribute inside the HyperLinkColumn

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

and remove the DataFormatString property
0
 
LVL 8

Expert Comment

by:PagodNaUtak
ID: 35005460
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
ID: 35005467
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
ID: 35092332
@CaringIT

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

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

786 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