matt2605
matt2605

Reputation: 216

Hyperlink URL causing resource not found error

I have a label created dynamically that displays content and a local link to files so that these can be downloaded or viewed in a browser.

label.Text="..content.." + " <asp:HyperLink runat=\"server\" NavigateUrl=\"~/c/customer/uploads/TestDocument.docx\">HyperLink</asp:HyperLink>";

I can use a hyperlink control or an <a> tag to display the link in the dynamic label and I can see the link address is basically correct except that Visual Web Developer 2010 Express automatically adds the root path as a prefix

http://localhost:50969/website/

to the path string followed by the URL I added enclosed inside 2 single quote quotation marks.

http://localhost:50969/website/'c/customer/uploads/TestDocument.docx'

When I click the link, the page throws resource cannot be found error. I think that the 2 single quotes are causing the error. Is there a way to remove the single quotes? Or is there a better technique to this?

Upvotes: 0

Views: 990

Answers (1)

VDWWD
VDWWD

Reputation: 35554

You are trying to add a asp.net Control as a string to a Label, but that will never work.

Either use the HyperLink control correctly by placing it on the aspx page and set the NavigateUrl property.

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/c/customer/uploads/TestDocument.docx">HyperLink</asp:HyperLink>

Or create a "normal" hyperlink as a string.

label.Text = "..content..<a href=\"~/c/customer/uploads/TestDocument.docx\">HyperLink</a>";

Upvotes: 1

Related Questions