Solved

Browse for a directory instead of browse for files

Posted on 2003-10-30
21
304 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Hi franse,

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

Author Comment

by:franse
Comment Utility
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
Comment Utility
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

Author Comment

by:franse
Comment Utility
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
Comment Utility
you do not have permissions?
what folder are you trying to get to?
0
 
LVL 15

Expert Comment

by:VincentPuglia
Comment Utility
what is your environment? browser, etc.etc.
0
 

Author Comment

by:franse
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

744 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

19 Experts available now in Live!

Get 1:1 Help Now