Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 20th, 2011, 05:53 AM
Registered User
 
Join Date: May 2006
Location: Lichfield, , United Kingdom.
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>
Reply With Quote
  #2 (permalink)  
Old June 20th, 2011, 06:35 AM
Imar's Avatar
Wrox Author
Points: 67,332, Level: 100
Points: 67,332, Level: 100 Points: 67,332, Level: 100 Points: 67,332, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 16,231
Thanks: 66
Thanked 1,418 Times in 1,398 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!
Reply With Quote
The Following User Says Thank You to Imar For This Useful Post:
hemo (June 20th, 2011)
  #3 (permalink)  
Old June 20th, 2011, 07:07 AM
Registered User
 
Join Date: May 2006
Location: Lichfield, , United Kingdom.
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
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 12: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



All times are GMT -4. The time now is 05:52 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.