Solved

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

Posted on 2006-06-13
5
1,672 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
crm written in asp.net / c# 1 42
Hovering effect 9 30
Visual Studio: built-in keystroke automation 2 26
Achieve json result 2 35
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now