Solved

how to location.href to a full filename (pdf file)

Posted on 2006-06-13
5
1,693 Views
Last Modified: 2012-06-21
When I click on a hyperlink for an asp.net file link utility I'm trying to write, I can't figure out how to get the file to open.

Is there something special I need to do to open files that are hyperlinked?

If the file is in the wwwroot during my test, I can open as long as it is not fully extended:

For example:

location.href=""MyFolder\report.pdf"""

That works.

But when I try to fully extend it, it doesn't work.

"location.href=""C:\Inetpub\wwwroot\MyProj\MyFolder\report.pdf"""

That doesn't work.

What am I doing wrong? Why can I shortcut to the file, but when I want to use the full filename, it doesn't work? Ultimately I want to point to files outside the wwwroot, but I'm starting here as a test.




0
Comment
Question by:TZych
5 Comments
 
LVL 14

Accepted Solution

by:
Thandava Vallepalli earned 500 total points
ID: 16897900
Hello,

>>but when I want to use the full filename, it doesn't work?

You should not put full file path in the location.href property.   wwwroot is the starting location of the webserver.  So web server doesn't know C:\Inetput location. It knows from only the wwwroot folder (i.e. root folder of the web server).  



>>Ultimately I want to point to files outside the wwwroot, but I'm starting here as a test.

You should not point the files which are outside of the wwwroot in location.href property...   As I explained you in above paragragh, web server file path starts from wwwroot folder.  So if you want to point outside wwwroot folder, you copy those files into wwwroot subfolders. then it works...

I hope you understand.....

Please let me know in case of any issues in this regard...

itsvtk
0
 
LVL 8

Author Comment

by:TZych
ID: 16897962
the webserver is the same machine where the files are.

it knows about D:\ and C:\

I have hyperlinked to them, but how do I open them with hyperlinkd?
0
 
LVL 8

Author Comment

by:TZych
ID: 16898017
Let me rephrase that.

The files are on the same machine as the webserver.

How can I open them via hyperlinks? I can see them as hyperlinks, but it won't open them.
0
 
LVL 24

Expert Comment

by:DBAduck - Ben Miller
ID: 16899252
What the problem is, is that when you try to use a href or a Hyperlink, you cannot reference c:\something\something.pdf because you are in a http context and the browser can understand that, but there is no file on your local machine with that path or name.  So the href is going to have to be /wwwrootname/folder/file.pdf instead.

For example:

location.href=""MyFolder\report.pdf"""

That works.
>> this works because it is relative to the wwwroot.

But when I try to fully extend it, it doesn't work.

"location.href=""C:\Inetpub\wwwroot\MyProj\MyFolder\report.pdf"""

That doesn't work.
>>> This does not work because of the href property being set to a physical path instead of a virtual path.

What am I doing wrong? Why can I shortcut to the file, but when I want to use the full filename, it doesn't work? Ultimately I want to point to files outside the wwwroot, but I'm starting here as a test.

>> so it should be
location.href="/MyProj/MyFolder/report.pdf"

Ben.
0
 
LVL 4

Expert Comment

by:indu_mk
ID: 16900577
if u want to give hyperlink to a file outside ur web site directory, u can create a virtual folder that directory ... say, for eg ur file is c:\something\something.pdf , make C:\something a virtual directory named "something" and give the hyperlink as http://localhost/something/something.pdf
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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