Solved

Create a button to open a local directory

Posted on 2004-10-04
10
393 Views
Last Modified: 2012-08-14
Hi Guys, I want to create a button people can press that will open a standard network drive folder on their computer.  At the moment I'm achieving this using a HyperLink like:

<asp:HyperLink id="HyperLink1" runat="server" Visible="False" Target="_blank" NavigateUrl="file://I:\NewFolder\Projects\">Browse Projects Browse</asp:HyperLink>

Unfortuantly though this isn't too obvious, I need to create it more in a button.  I've tried server.transfer and response.redirect and even trying to open the folder in an <IFrame> but with no success.

Can anybody help?
0
Comment
Question by:Stamper
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 12217293
You can try adding the following code to the button:

void Page_Load(object src, EventArgs e)
{
    myButton.Attributes.Add("OnClick","javascript:window.open(\"file://I:\NewFolder\Projects\\")");
}

Best, Nauman.
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12217317
Hi,

unfortunately you have no access on the user machine
with the example you've posted you open the folder on the server, not on the client

Regards,
B..M
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 12217360
mmarinov is exactly right, you will not be able to expose a clients file listing in your app without the use of an activex control, etc.  This would be a varitable Pandora's box of security issues and for this reason your requested functionality is not possible without a client plugin

Aeros
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 12217572
If you just want to open the explorer window to open the folder then I think you can do it easily as this javascript is working perfectly fine:

<input type="button" value="Button" name="B3" onClick="javascript:window.open('file:///c:/')">

What exactly are you trying to do? Can you explain?

Thanks, Nauman.


0
 

Author Comment

by:Stamper
ID: 12218538
Every computer on the network has access to a network drive.  On clicking the button - I want a Windows Explorer folder to launch up so they can browse around that file.  I don't want access to it.  I just want them to be able to see it on their own computer.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 17

Expert Comment

by:AerosSaga
ID: 12218571
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
   If Not IsPostBack Then
       Dim di As DirectoryInfo = New DirectoryInfo("c:\Events\HTML\Event\")
       Dim ds As DataSet = new DataSet()
       Dim fis as FileInfo()
       Dim fi as FileInfo()

       ds.Tables.Add()
       ds.Tables(0).Columns.Add("FileName")
       ds.Tables(0).Columns.Add("path")

       fis = di.GetFiles()
       For Each fi in fis
           Dim dr as DataRow = ds.Tables(0).NewRow()
           dr(0) = fi.Name
           dr(1) = "your web application virtual directory name" & fi.Name
           ds.Tables(0).Rows.Add (dr)
       Next

       ddlPages.DataSource = ds
       ddlPages.DataTextField = "FileName"
       ddlPages.DataValueField = "path"
       ddlPages.DataBind()

End Sub

Not sure if it will work with a mapped drive, but I think UNC shares are ok

Aeros
0
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 250 total points
ID: 12218632
Stamper,

Did you try using the code that I posted?

myButton.Attributes.Add("OnClick","javascript:window.open(\"file:///I:\NewFolder\Projects\\")");

-Nauman.
0
 

Author Comment

by:Stamper
ID: 12218756
yup nauman but it didnt work... but that code looks good and if i type the file:// into my run window then it pops up - which is what i want exactly.

So I think maybe the permisions could be set up wrong on my browser?
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 12218903
what error are you getting?

-nauman.
0
 

Author Comment

by:Stamper
ID: 12224967
nothings happening at all, the code looks fairly right and what I was after so I've accepted it.  I think I probobly need a good play around with my browser and its security settings
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

15 Experts available now in Live!

Get 1:1 Help Now