 |
| ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 12th, 2007, 01:24 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Accessing a Local Directory
Right i have a website that i want to link to Directory on a local machine. It works when i use the hyperlink ie
Code:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "file:///G:/PDF_Production/" + Request.QueryString("jobno").Insert(2, "-") %>'>HyperLink</asp:HyperLink>
But i want to use some error checking on the file to make sure that there is an actual directory. The code that i am using is
Code:
Dim filename As String = "file:///G:/PDF_Production/" + Request.QueryString("jobno").Insert(2, "-")
If (IO.Directory.Exists(filename) = True) Then
Dim popupScript As String = "<script language='javascript'>window.open('" & filename & "');</script>"
ClientScript.RegisterClientScriptBlock(Me.GetType(), "PopupScript", popupScript)
Else
Dim popupScript As String = ("<script language='javascript'>alert(""There was nop PDF_Production Folder for this Job"");</script>")
ClientScript.RegisterClientScriptBlock(Me.GetType(), "PopupScript", popupScript)
End If
How come this does not work when it is exactly the same. I know it has something to do with security but if that was the case how does the hyperlink work and the javascript does not. Or is there any way that i will be able to do this on the local computer. All file directorys are fake as well!!
|
|

January 12th, 2007, 01:36 PM
|
|
Wrox Author
|
|
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
|
|
It has been my experience that the IO classes do not like UNC path's, moreover, anytime I use anything from the IO classes I have to use Server.MapPath I think that is where your error lies.
-----------------------------------------------------------
I will only tell you how to do it, not do it for you.------------
Unless, of course, you want to hire me to do work for you.---
^^Thats my signature--------------------------------------
-----------------------------------------------------------
http://www.catb.org/~esr/faqs/smart-questions.html -------
^^Took that from planoie's profile--------------------------
-----------------------------------------------------------
|
|

January 12th, 2007, 01:39 PM
|
|
Friend of Wrox
|
|
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi,
I haven't tried your code, but I do know that you're dealing with two different user accounts in the two scenarios:
When a user clicks on a hyperlink, they are using their own account, wo if they have permissions on that directory/file, they're golden.
However, to execute code like...
Code:
If (IO.Directory.Exists(filename) = True)
ASP.NET uses the aspnet account, or I think a system account. You need to make sure that account has read/write access to the directory.
Aaron
|
|

January 12th, 2007, 01:44 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well i don't have any accounts set up so does that mean i have to set up an account. Right now i have a database with the list of users that can access certain pages. How can i just make everyone have access to the folder. Also i can't use server.mappath as the path is not on the server it is on the local machine that i want to be able to access the local paths.
|
|

January 12th, 2007, 03:48 PM
|
|
Friend of Wrox
|
|
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Oh. I get it now. Local machine means the browser's computer.
OK, well the bad news is that neither ASP.NET nor JavaScript have any access to the user's machine. ASP.NET can only access files on the web server, and JavaScript can't operate outside the browser window as a security measure.
You can, as you've discovered, create hyperlinks to local files. But that's about it.
Aaron
|
|

January 12th, 2007, 04:03 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Is there any way that i could get around this. I just want to be able to link to the directory so can i run some kind of html script to do it or does someone have any ideas on how it can be done.
|
|

January 12th, 2007, 05:36 PM
|
|
Friend of Wrox
|
|
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
You can write a Java Applet or ActiveX control, but I think most users would have this blocked. Actually, while I'm not a Java developer, I don't even think Java Applets can access the browser's hard drive.
Aaron
|
|

January 12th, 2007, 06:10 PM
|
|
Authorized User
|
|
Join Date: Jan 2007
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Well i was just thinking is there a way that i could create HTML code on the fly that would allow me to create the necessary hyperlink. In otherwords can i keep all the processing i have done and then if there is not an option instead of showing the hyperlink then i would just not show it on the page. I know when using php i can do this but i am not sure if ASP.Net can create html code like php does. I will need to check to see if a particular directory is there and if it is there then to create the necessary hyperlink and if not there then don't display it.
On another note. How is it that the hyperlink can bypass this so called security and asp.net cannot.
|
|

January 12th, 2007, 06:39 PM
|
|
Friend of Wrox
|
|
Join Date: Apr 2004
Posts: 204
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Again,
ASP.NET, which is a server-side technology, has no access to the browser's hard drive. Period.
You can create a hyperlink to anything anywhere. It doesn't even have to exist. Here's one: http://www.someimaginarypage.com/myNonFile.doc.
If the user has access to the path that the hyperlink specifies, then they can retreive the link. If not, it is a broken link, and they'll get an error when they click the link.
JavaScript cannot access the local hard drive by design. This is a security feature, and can't be bypassed. My understanding is that Java also works in a "sandbox" mode, which protects the user's machine from malicious code. ActiveX however doesn't not have this protection, which is why most users have it turned off.
Maybe you should move the file onto the web server instead.
Good luck.
|
|
 |