Link to home
Start Free TrialLog in
Avatar of franse
franse

asked on

Browse for a directory instead of browse for files

Hello,

Normaly in ASP with a browse button you open a browse window and you browse for files. But can this work for directory's as well?
I like to catch a directory path and write it to a DB.

Points go to someone who has the code for this functionality.

Thanks,

frans
Avatar of VincentPuglia
VincentPuglia

Hi,

since I tested this on my machine and not the web, you may have to switch ("\\") to ("/")
function doit(formObj)
{
  x = formObj.b.value.lastIndexOf('\\')
  formObj.c.value = formObj.b.value.substring(0,x)
}

//-->
</script>
</head>
<body>
<form name="a">
<input type="file" name="b">
<input type="text" name='c'>
<input type="button" onclick='doit(this.form)'>
</form>
try this, this is example from MSDN uses shell object.


<SCRIPT LANGUAGE="JavaScript">
<!--
  function fnGetMyPathJ()
  {            
    var oShell = new ActiveXObject("Shell.Application");
                      
    var oFolder = new Object;                              
    oFolder = oShell.BrowseForFolder(0, "Choose a folder", 0);
                                        
    var oFolderItem = new Object;            
    oFolderItem = oFolder.Items().Item();                                                
   
    document.all.item("myPath").innerText = oFolderItem.Path;
  }    
-->
</SCRIPT>
Avatar of franse

ASKER

Sorry VincentPuglia your code does not work.


Hello appari,

I can't get your code working either,
But can you please deliver the code I need in ASP to call for it?
like VincentPuglia did.

Thanks,

franse
ok try this

<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
  function fnGetMyPathJ()
  {          
    var oShell = new ActiveXObject("Shell.Application");
                   
    var oFolder = new Object;                        
    oFolder = oShell.BrowseForFolder(0, "Choose a folder", 0);
                                 
    var oFolderItem = new Object;          
    oFolderItem = oFolder.Items().Item();                                        
   
    document.all.item("myPath").innerText = oFolderItem.Path;
  }    
-->
</SCRIPT>
</head>
<body>
<form name="a">
<input type="TEXT" name='myPath'>
<input type="button" value="Browse" onclick='fnGetMyPathJ()'>
</form>
</body>
Avatar of franse

ASKER

Appari,

The script returns an error:

Permission denied in line 9 character 5

Line 9 =
    oFolder = oShell.BrowseForFolder(0, "Choose a folder", 0);

thanks,

franse
Hi franse,

   I just uploaded it to: http://members.aol.com/grassblad/clients/getDir.html

  It browses my computer, allows me to pick a file, and then by hitting the button, puts the non-filename portion of the path in the second text box.
  The only thing I added was an alert
What doesn't work?

Vinny
Avatar of franse

ASKER

Sorry VincentPuglia,

Now I understand your sollution.
But it is not what I was looking for. The sollution should also work for directories that contain only subdirectories. Correct me if I am wrong, but I think this will not work in those cases.

Thanks,

franse

Hi franse,

  You're correct.  you're looking for an IE-only solution?
Avatar of franse

ASKER

yes

The sollution will be used in an intranet application so I am shure the clients all work with IE5.5 or higher.

ASKER CERTIFIED SOLUTION
Avatar of VincentPuglia
VincentPuglia

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 franse

ASKER

VincentPuglia,

This script results in the same error:

Permission denied in line 9 character 3

Line 9 =

oFolder = oShell.BrowseForFolder(0, "Choose a folder", 0);


thanks,

franse
you do not have permissions?
what folder are you trying to get to?
what is your environment? browser, etc.etc.
Avatar of franse

ASKER

By the way this is the URL of the test site I use:

http://www.erich.nu/erich/test/test.asp
1) that is a secure site -- and it didn't even put up the browse dialog when I tried.
2) you probably need read permissions
Avatar of franse

ASKER

No the site has a front door but the back door is open.

But ok an other profider and other site with no protection:

http://www32.brinkster.com/monnik/test.asp

same error
Hi franse,

  Sorry to say but there seems to be some reason for it not to work on the web.  I uploaded my example here:

http://members.aol.com/grassblad/clients/getDir.html

as well as a different M$ example that uses the shell.app... here:

http://members.aol.com/grassblad/clients/getFolderItem.html

while both work locally, they both fail ungracefully (without error messages) on the net.  All of this means to me that something on the web is preventing the activexobject from executing as it should.

Vinny
Avatar of franse

ASKER

OK your right it works localy. And for now this will do.

If one of the experts knows how to get this functionality working on an INTRAnet sollution I am willing to give some points for that answer too. Let's say 200 points

one question ramains how to devide the points?
The points to devide are 125 in this Javascript question.
200 points in the ASP section
20 points in the VB section

Thanks,

franse

Hi franse,

   I presume you mean you have asked the same question in 3 places and that at least in one of them no one responded.  You can have the points refunded,  refunded and increased, or have the 'user' post in the empty question and then award the points there.  

   It really depends on how much the 'points' mean to you.  (They buy me neither cigarettes nor espresso, so I don't really care.)  If you look at the 'experts' rank and/or point total before looking at his/her solution, then hand out as many points as you want.  

Vinny
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: VincentPuglia {http:#9658692}

Please leave any comments here within the next four days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer