Forum Moderators: open

Message Too Old, No Replies

Downloading Files from Folder with Hyperlink

         

latoc

7:55 pm on Jun 18, 2011 (gmt 0)

10+ Year Member



I am downloading pdf files directly from the uploads folder in the root of the website, using the basic code below for test.
This displays the files as an hyperlink as required allowing selected files to opened. However, when clicked to open the file
it’s not found; Error 404 Requested URL: /Newsletter1.pdf. The uploads folder path seems to be missing.Is there a way to download the complete path in order that they may be opened?

<script type="text/vbscript" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
Dim dirInfo as New DirectoryInfo(Server.MapPath("~/uploads/"))
articleList.DataSource = dirInfo.GetFiles("*")
articleList.DataBind()
End Sub
</script>

<body>
<form id="form1" runat="server">
<asp:GridView runat="server" id="articleList"
AutoGenerateColumns="False"
HeaderStyle-BackColor="Navy" HeaderStyle-ForeColor="White"
HeaderStyle-Font-Size="15pt" HeaderStyle-Font-Bold="True">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="name" DataTextField="name"
HeaderText="Newsletter Files"/>
</Columns>
</asp:GridView>
</form>
</body>

Ocean10000

2:04 pm on Jun 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



try adding DataNavigateUrlFormatString

see below
<asp:HyperLinkField DataNavigateUrlFields="name" DataNavigateUrlFormatString="~/uploads/{0}" DataTextField="name"
HeaderText="Newsletter Files"/>

latoc

3:54 pm on Jun 20, 2011 (gmt 0)

10+ Year Member



Many thanks for you response. Your solution works fine, all files can now be downloaded.

latoc