Solved

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

Posted on 2007-11-14
7
536 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ISS migration from IIS 6 to IIS 8.5 rendering problems 4 51
Different Delete Messages 7 37
Adjust the position 3 49
C#  Radio button search for Date not DateTime 4 35
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

896 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now