Link to home
Start Free TrialLog in
Avatar of Stamper
Stamper

asked on

Create a button to open a local directory

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?
Avatar of nauman_ahmed
nauman_ahmed
Flag of United States of America image

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.
Avatar of mmarinov
mmarinov

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


Avatar of Stamper

ASKER

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.
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
ASKER CERTIFIED SOLUTION
Avatar of nauman_ahmed
nauman_ahmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Stamper

ASKER

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?
what error are you getting?

-nauman.
Avatar of Stamper

ASKER

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