Solved

Create a button to open a local directory

Posted on 2004-10-04
10
395 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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
 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

786 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