Solved

ASPX directory listing

Posted on 2011-03-01
5
204 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

840 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