Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


browsing for a file

browsing for a file

browsing for a file

Hello all!

I'm writting an HTML document where part of the functionality lets the user browse for a folder, and in another place to browse for a file. After searching through many threads, I've found that the following code works for the folders:

Set objFolder = objShell.BrowseForFolder(0, "Select a folder:", &H0)

and the following code works for files:

<input type="file" name="myFile">

However, these two methods display different dialogue boxes, and I'm trying to achive continuity. The BrowseForFolder function does not work when selecting files, and I can't find any HTML code to return a folder. Does anyone know how to do either of these two things, or yet a third option that will achive both? I am espescially interested in the vbScript method because I will be able to use it in non-html programs.

Thanks all for your help.

RE: browsing for a file

does this help?

Set ObjFSO = CreateObject("UserAccounts.CommonDialog")

ObjFSO.Filter = "VBScripts|*.vbs|Text Documents|*.txt|All Files|*.*"

ObjFSO.FilterIndex = 3

ObjFSO.InitialDir = "c:\myscripts"

InitFSO = ObjFSO.ShowOpen

If InitFSO = False Then
    Wscript.Echo "Script Error: Please select a file!"
    Wscript.Echo "You selected the file: " & ObjFSO.FileName
End If

RE: browsing for a file


set oFO = CreateObject("SAFRCFileDlg.FileOpen")
' exposed in safrcdlg.dll
wscript.echo oFO.FileName

RE: browsing for a file

Thanks for the input, but I get the following error:

Error: ActiveX component can't create object: 'SAFRCFileDlg.FileOpen'

which probably means I need to download the appropriate dlls. I do now know if that will be acceptable to our LAN team, so if there are other alternatives, I would be appriciative to hear them!


RE: browsing for a file

hi 1974, im afraid thats the only details ive got.

have you tried my first post??? this works for me and doesnt require an additional dll...

RE: browsing for a file

Hello Programmer1984,

[1] Safrcfiledlg.fileopen is with xp.

[2] For simulation using file selection using input, type="file" msie browser, you can dynamically make htm file for systematic use by calling a pre-fabricated block of code. That is the cheapest and most probably useable for windows platform. You can mimic or use one from jsware:
in particular, the fileopen.vbs.

[3] If it is more a developers/technical environment where you think most get vb package installed (a commercial visual studio or ms free vb5 editor) then you have all the necessary licence to use comdialog.ocx. With it installed, you can do something neat, like this.


set ocomdlg=createobject("mscomdlg.commondialog")
with ocomdlg
    .dialogtitle="select a file"
    .filter="All files (*.*)"
    .maxfilesize=10000    'filter filesize
end with
wscript.echo filespec
These two are the solution to get scripter by I would prefer.

regards - tsuji

RE: browsing for a file

Thanks all for the help, but I still havn't quite found what I'm looking for.

mrmovie, I do get an error with your first example, which is that activeX can't create the object. I'll keep trying though.

tsuji, the vbScript that you've provided from the download was cool, but it's basically the same thing I have above where it uses the HTML: <input type="file" name="myFile">. I did provide me with some ideas for other scripts though.

Also, none of us have VB Studios, or anything like that. We're mostly a mainframe COBOL shop, so my options are limited to straight VB/HTML code. I may venture in to JScript if all else fails.

Please let me know if there are more ideas out there! Thanks again!

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close