1

ASP.NET application on the default page I have to create two links that refer to PDF files.

Example:

<a href="Private/UserDocs/SIPCustomerUserGuideV2-2013.pdf" target="_blank">

Code structure where the PDF file exists is:

Web.FormProject/Private/UserDocs/SIPCustomerUserGuideV2-2013.pdf     

Above Web.FormProject is a folder, Private is a sub folder in Web.FormProject and UserDocs is a sub folder under Private folder. And the file resides in UserDocs.

When I try using the above the URL gives me nothing not even an error.
But when I change my hyperlink to after putting the file in the Web.Form project (and not under any sub folder) it works fine.

I have even tried the same with asp:hyperlink does not work. It only worked when I tried it with asp:LinkButton with code in the server side but the Content:Disposition "inline: ... in the Response.AppendHeader("Content-Disposition", "inline; filename=SIPCustomerUserGuideV2-2013.pdf"); opens it in the same browser and I want it to open in a new browser" But I would like a solution to use it as a hyperlink given above. Please reply.
Question:

How do I make it the PDF open from the Web.Form Project/Private/UserDocs/path.
thanks in advance.

2 Answers 2

1

Try:

<a href='<%= ResolveUrl("~/Private/Docs/UserGuide.pdf") %>' target="_blank">Link To PDF</a>

The ResolveUrl() method will resolve to the full path.

EDIT

After some chat we found out he had a configuration:

<location path="Private"> 
<system.web> 
<authorization> 
<deny users="?"/> 
</authorization> 
</system.web> 
</location> 

That disable the users not logged in to download files.

Sign up to request clarification or add additional context in comments.

9 Comments

I tried : <a href='<%= ResolveUrl("~/Private/UserDocs/SIPCustomerUserGuideV2-2013.pdf") %>'target="_blank" >User Guide</a> still no luck. thank you.
What do you mean by no luck? An error? did not download? what did you get?
It did not open at all. Why would it open when I put the file in root. But does not open when I put the file in a sub folder.
Because you are not resolving the file path correctly. The ResolveUrl works like this: ResolveUrl("~/SubFolder/OtherSubfolder/File.PDF") where ~/ means the root.
Hanlet - Super thanks again for your effort and help. God Bless you.
|
0

Try resolving it from the root and don't forget to add the runat attribute:

<a href="~/Private/UserDocs/SIPCustomerUserGuideV2-2013.pdf" 
    target="_blank" runat="server">Link</a> 

3 Comments

Hi. When the page first load this is the URL in the browser:localhost:60837/LogOn.aspx. I tried doing what you said it still does not open the PDF instead it displays the same LogOn.aspx page.
Do you have name and password to login?
Yes I have name and password to login. But this does not require login. This is a PDF on the logon page which will open when you click it. Any ideas?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.