Solved

Browse for a directory instead of browse for files

Posted on 2003-10-30
21
305 Views
Last Modified: 2008-03-06
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
0
Comment
Question by:franse
  • 9
  • 8
  • 2
  • +1
21 Comments
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9654409
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>
0
 
LVL 39

Expert Comment

by:appari
ID: 9655333
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>
0
 

Author Comment

by:franse
ID: 9655546
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
0
 
LVL 39

Expert Comment

by:appari
ID: 9655759
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>
0
 

Author Comment

by:franse
ID: 9656237
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
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9657316
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
0
 

Author Comment

by:franse
ID: 9657974
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

0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9658079
Hi franse,

  You're correct.  you're looking for an IE-only solution?
0
 

Author Comment

by:franse
ID: 9658328
yes

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

0
 
LVL 15

Accepted Solution

by:
VincentPuglia earned 125 total points
ID: 9658692
using appari's script:
<html><head>
<script language='javascript' type='text/javascript'>
<!--
function fnGetMyPathJ(formObj)
{  
  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();                            
  formObj.parentFolder.value = oFolder.Items().Item();
  formObj.fullPath.value = oFolderItem.Path;
  }    
-->
</SCRIPT>
</head>
<body>
<form name="a">
<input type="TEXT" name='fullPath'>
<input type='text' name='parentFolder'>
<input type="button" value="Browse" onclick='fnGetMyPathJ(this.form)'>
</form>
</body>
</html>

Vinny
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:franse
ID: 9660344
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
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9660361
you do not have permissions?
what folder are you trying to get to?
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9660363
what is your environment? browser, etc.etc.
0
 

Author Comment

by:franse
ID: 9660366
By the way this is the URL of the test site I use:

http://www.erich.nu/erich/test/test.asp
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9660390
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
0
 

Author Comment

by:franse
ID: 9662348
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
0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9671394
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
0
 

Author Comment

by:franse
ID: 9677028
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

0
 
LVL 15

Expert Comment

by:VincentPuglia
ID: 9678295
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
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10346381
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
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

863 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

27 Experts available now in Live!

Get 1:1 Help Now