Solved

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

Posted on 2007-11-14
7
538 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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