Solved

Use Hyperlink or LinkButton controls on a page to download documents from server?

Posted on 2007-11-14
7
540 Views
Last Modified: 2012-05-05
Hi, I need to provide a page with links to download files from the server.  However, I am not sure what would be an ideal control to use for this scenario?  Would it be Hyperlink or LinkButton?  
The names of the files are never the same.  Upon clicking on the links, the code needs to get the server path from the web.config file and the filename would have to be built based on the ID of the case selected.  It is also important that the link is reusable to download the file again without having to refresh the page.

I truely appreciate your time and assistance on this.
Thank you so much!
0
Comment
Question by:LISCNY
  • 4
  • 3
7 Comments
 
LVL 16

Expert Comment

by:McExp
ID: 20285040
Do you need to open in the same window or a new window?
0
 

Author Comment

by:LISCNY
ID: 20286684
The download dialog box should pop up when links are clicked on the page.  The users typically save the files on their local drive, but if they open the file from the dialog, it would open on a new document window.  However, the user should be able to close the opened document window and see the page with links.

Thanks for your time!
0
 
LVL 16

Expert Comment

by:McExp
ID: 20290915
Then you need a hyperlink control.
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:LISCNY
ID: 20291027
Thank you.  Would you be able to refer me to a sample code?
0
 
LVL 16

Accepted Solution

by:
McExp earned 500 total points
ID: 20293739
During the PageLoad event (of your page) you need to set the NavigateUrl of a Hyperlink control, see below for an example: -

--In your page--
<asp:HyperLink runat="server" ID="hlTheLink" Text="Open Document" />

--In your Page Load Event of the Code Behind--
string theUrl = BuildUrlFromWebConfigAndCase(CaseId);
hlTheLink.NavigateUrl = theUrl;

--Write a function to compise the URL you need--
private string BuildUrlFromWebConfigAndCase(int CaseId)
{
//Some Code
}
0
 

Author Comment

by:LISCNY
ID: 20294084
My boss just told me to do this using LinkButtons so I was able to get the desired result using LinkButtons.  Thank you for all your assistance.
0
 
LVL 16

Expert Comment

by:McExp
ID: 20299622
The only issue with the LinkButton alternative is that it requires an aditional postback to your web server to then redirect to the actual file. Whereas the Hyperlink will load the file directly.

The Hyperlink based solution is the marginally better (faster) solution.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
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…
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…

830 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