Solved

ASPX directory listing

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
LINQ - C# to VB convertion 12 46
What .NET URL re-routing tool did I use? 2 37
Split in Javascript 5 31
Displaying a web form as a modal popup dialog box. 4 22
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

910 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

23 Experts available now in Live!

Get 1:1 Help Now