Home All Groups Group Topic Archive Search About

Problems adding HyperLink controls through code.

Author
5 Jul 2009 3:38 AM
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

Author
5 Jul 2009 9:28 AM
Mark Rae [MVP]
"mete hanap" <mete.ha***@gmail.com> wrote in message
news:6241ebe1-364a-4461-9e96-015808c2e617@m3g2000pri.googlegroups.com...

> Any help is appreciated.

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"


--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Are all your drivers up to date? click for free checkup

Author
8 Jul 2009 12:22 AM
forest demon
Show quote Hide quote
On Jul 5, 3:28 am, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:
> "mete hanap" <mete.ha***@gmail.com> wrote in message
>
> news:6241ebe1-364a-4461-9e96-015808c2e617@m3g2000pri.googlegroups.com...
>
> > Any help is appreciated.
>
> 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"
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


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

what am i missing?

thanks....
Author
8 Jul 2009 12:53 AM
Mark Rae [MVP]
"forest demon" <mete.ha***@gmail.com> wrote in message
news:7239f7eb-0aa7-45aa-a482-2b57031eda0d@x6g2000prc.googlegroups.com...

>> 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?

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


--
Mark Rae
ASP.NET MVP
http://www.markrae.net
Author
8 Jul 2009 2:33 AM
forest demon
Show quote Hide quote
On Jul 7, 6:53 pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:
> "forest demon" <mete.ha***@gmail.com> wrote in message
>
> news:7239f7eb-0aa7-45aa-a482-2b57031eda0d@x6g2000prc.googlegroups.com...
>
> >> 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?
>
> 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
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net

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...

Bookmark and Share