# ASP doesn't opens files



## mad1231moody (Feb 6, 2008)

Hi friends, got a query and need solution as soon as I can. You may be knowing that in HTML if we use this


> <a href="file://C:\WINDOWS"> Open</a>


When I click on open it opens WINDOWS folder in Explorer. But this is not the case in asp. Although when I bring the mouse on the link in ASP, I get the same path as I get in HTML,i.e 


> file:///C:\WINDOWS


But when I click it nothing happens.So please tell me a way on how do I open files and folders in asp.

Another query 



> <% @language=VBScript %>
> <% Option Explicit %>
> <% dim str
> str="file://C:\WINDOWS"
> %>


Now I want this string to be passed in an HTML file,and use it in 
<a href="file://C:\WINDOWS"> in the html file. Please guide if this is possible. waiting for your response


----------



## Rollercoaster (Feb 6, 2008)

i tried what u said and it truly doesn't work. i found thru trial n error that it works for files under the website directory only. may be there is some property we need to specify or un-specify that is causing this.


----------



## mad1231moody (Feb 6, 2008)

Yes it does opens files .jpg, .txt . But it is unable to open folders in win explorer. Do you have an answer for my second query


----------



## amitava82 (Feb 7, 2008)

can't you just echo out the 'str'?
IN PHP we do like this:
<a href="<?php echo $str; ?> ">Click me</a>
So, in asp echo out the str in a asp tag..


----------



## mad1231moody (Feb 7, 2008)

Well can u please make sure if echo can be used in asp. Cause I am not using php for this purpose


----------



## amitava82 (Feb 8, 2008)

Try this:
<%=str%>


----------



## mad1231moody (Feb 9, 2008)

So you say I should try like this


> <a href=<%=str%>>Click me</a>


----------



## amitava82 (Feb 9, 2008)

<a href="<%=$str%>">Click me</a>

Why not you just try it rather than asking for confirmation!


----------



## mad1231moody (Feb 9, 2008)

Well mate it is not working  . Please if any more tricks u can get please


----------



## Rollercoaster (Feb 11, 2008)

try    

```
<a href="
            <%
            string str = @"*www.thinkdigit.com";
            Response.Write(str); 
            %>
            ">sometext</a>
```

works with web addresses but it will still not open any file with the file:///

note- code in c#


----------



## mad1231moody (Feb 11, 2008)

Well mate that is the real prob, I want the file:/// to open. */ works fine anyways


----------



## Rollercoaster (Feb 11, 2008)

if u can tell here what u want to build that may be i can give better alternatives.

you can also try to use a asp:HyperLink with this code in its click event

           System.Diagnostics.Process.Start(@"c:\windows");

or open a pop up self closing window with 
<%
System.Diagnostics.Process.Start(@"c:\windows");
%>


----------



## mad1231moody (Feb 12, 2008)

Mate I am preparing a search engine. As you know that the *FolderExists* and *FileExists* method of the *FileSystemObject* can be used to find out a file or folder exists on the server or not. In my case the server is localhost.
The *Getfile* method can then be used to find the attributes like Date last modified,Last accessed and *Path. *Now what I want to do is open the path that I get. I thought that using <a href=path> will be the best idea, but it is not so. *@Rollercoaster* the code you gave in above post, can u write a sample basic code and post it here. As I am not familiar with the code you have written. I hope I can get some help


----------



## Krazy_About_Technology (Feb 12, 2008)

Rollercoaster said:


> if u can tell here what u want to build that may be i can give better alternatives.
> 
> you can also try to use a asp:HyperLink with this code in its click event
> 
> ...



Dude he is not using ASP.NET, its vanilla ASP.

Now as for your problem, the code that writes the exact line in the browser is :


```
<a href=<% response.write(chr(34) & "file://c:/" & chr(34)) %>>Open C Drive</a>
```

But if you run it as an asp page it wont open the c drive even when the html code is correct. You can check this by using View Source and then copying and pasting the html code in a local html file.

The reason for this is when an asp page is served, it is first parsed using the asp parser isapi dll on iis. Then iis sends the resultant html to client. Now all the html when arrives on client is first stored in the temporary internet files folder (or the cache) and then it is displayed. That folder is a special system folder and is protected. You cant run any system commands from there an thats why the link is not working. 

Although i am aware that there is a way to bypass this, i cant remember it now. I'll post back when i get it again. Ok.


----------



## Rollercoaster (Feb 12, 2008)

i was under the impression that we are talking abt asp.net...

i have zero idea abt asp. never ever used it. started directly with .net

the best way would be to ask some javascript guru to write u a page start executing code which does-

1. hyperlink to open a popup/invisible windows
2. open the file/folder from that window
3. popup window closes itself


----------



## mad1231moody (Feb 12, 2008)

Krazy_About_Technology said:


> Dude he is not using ASP.NET, its vanilla ASP.
> 
> Now as for your problem, the code that writes the exact line in the browser is :
> 
> ...


Thanks Crazy for the xplanation mate. Now I know that it is not possible to open folders. I hope u get the solution soon. Please mate m in hurry



Rollercoaster said:


> i was under the impression that we are talking abt asp.net...
> 
> i have zero idea abt asp. never ever used it. started directly with .net
> 
> ...


@Rollercoaster thanks for the ideas, but I have  not got what u wanna say. SUre I have books for Javascript but can't make out much from them. Please I am a noob and would like you to post a sample code. Please I request again!!


----------



## Rollercoaster (Feb 12, 2008)

i donno javascript either. you should post on some javascript/asp forum instead of here. 
try- forums.aspfree.com , www.webdeveloper.com/forum/forumdisplay.php?f=3 and search google for more

i tried giving tips as much as i could but i cant do ur work for u..


----------



## mad1231moody (Feb 12, 2008)

Its alright coaster, I thought that you might be knowing Javascript. Thanks for the tips. Hope crazy gets the idea soon


----------



## Krazy_About_Technology (Feb 13, 2008)

Yaar i dont think its gonna work. When working from ASP, you are an alien for the system. It wont allow any such thing. i even tried with this javascript based code :


```
<html>
<head><title>ASP Page</title></head>

<body>

<script language='javascript'>

function openwnd(pth)
{
 window.open(pth);
}

</script>

<a href="#" onClick=<% response.write(chr(34) & "javascript:openwnd('file://c:/');" & chr(34)) %>>Open C Drive</a>

<body>
</html>
```

I think you are out of luck


----------

