Solved

Create a button to open a local directory

Posted on 2004-10-04
10
397 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

856 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