Link to home
Start Free TrialLog in
Avatar of TZych
TZychFlag for United States of America

asked on

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

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.




ASKER CERTIFIED SOLUTION
Avatar of Thandava Vallepalli
Thandava Vallepalli
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TZych

ASKER

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?
Avatar of TZych

ASKER

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.
Avatar of DBAduck - Ben Miller
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.
Avatar of indu_mk
indu_mk

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