Problems adding HyperLink controls through code.

M

mete hanap

For example, I loop through a list of strings that are paths to .pdf
files and create HyperLink controls to add to a PlaceHolder control.

The HyperLinks get created accordingly but when clicked, they do
nothing.


List<string> dirs = FileHelper.GetFilesRecursive(newsLettersPath);
foreach (string p in dirs)
{
HyperLink hlNewsLetter = new HyperLink();
hlNewsLetter.ID = p;
hlNewsLetter.Text = p + "<br>";
hlNewsLetter.Target = "_new";
hlNewsLetter.NavigateUrl = p;

placeHolder_NewsLetters.Controls.Add(hlNewsLetter);
}


any help is appreciated.

thank folks...

-
fd
 
F

forest demon

When the page has been created, do a View Source - what do the individual
href tags of the hyperlink markups look like...?

I'm guessing they look something like
href="C:\\\\MyServer\\MyFolder\\MyFile.pdf"


yes mark, that's exactly what they look like. embedded within an <a>
tag.

what am i missing?

thanks....
 
F

forest demon

Hyperlinks must be resolvable relative or absolute addresses. In the example
above, you have told the web browser to try to load PDF documents on the
local C:\ drive. Apart from the fact that these files don't exist on the C:\
drive of the computer on which the web browser is running (they're on the
C:\ drive of the web server), security restrictions in all modern browsers
would disallow access to local resources like this anyway...

You have two choices:

1) ensure that these documents are available to the client browsers are
resolvable URLs

2) open the documents on the server as binary files and stream them to the
client browser that way

1) above is by far the simplest - simply copy the files into the same
virtual directory as the web application and reference them as if they were
an aspx page

thanks mark. i figured out what i was doing wrong. it had more
to do with the way i was doing my recursion and what was being
output.

i appreciate your time...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top