Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
|
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 20th, 2011, 05:53 AM
Registered User
 
Join Date: May 2006
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default Downloading Files from Folder with HyperLink

I am downloading pdf files directly from a folder 'uploads' in the root of the website, using the basic code below for test.
This displays the files as a live hyperlink as required, however, when clicked to open the file; Error not found; Error 404 Requested URL: /Newsletter1.pdf. The uploads folder path seems to be missing, preventing the selected files from being viewed. I have changed the UrlFields and TextFields to 'FullName' which does display the full root of the files, but now although displayed as live links they are no longer active.

I have tried a multitude of variations without success. Can anyone Help please?
Code:
<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>
 
Old June 20th, 2011, 06:35 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You can use the DataNavigateUrlFormatString property of the HyperLink control to change the full URL. Something like this should work:

DataNavigateUrlFormatString="~/Uploads/{0}"

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
hemo (June 20th, 2011)
 
Old June 20th, 2011, 07:07 AM
Registered User
 
Join Date: May 2006
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default Downloading Files from Folder with HyperLink

Hi Imar

Fantastic!!!!!
It now works as planned. Thanks VERY much for you response and solution.

Regards
hemo





Similar Threads
Thread Thread Starter Forum Replies Last Post
Downloading files via a browser gfrank1157 ASP.NET 2.0 Basics 3 June 14th, 2006 04:13 PM
Problem downloading sensitive files mat41 Classic ASP Professional 1 May 4th, 2006 08:45 PM
Protect Files from downloading asif_sharif ASP.NET 1.0 and 1.1 Professional 6 January 11th, 2006 01:59 AM
Up/downloading Files VB+MySQL mike123abc Pro VB 6 3 May 24th, 2004 03:56 AM
downloading files serge Classic ASP Professional 4 September 8th, 2003 10:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.