Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

browsing for a file 2

Status
Not open for further replies.

Programmer1974

Programmer
Joined
Feb 19, 2004
Messages
33
Location
US
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.
 
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.Quit
Else
Wscript.Echo "You selected the file: " & ObjFSO.FileName
End If
 
or

set oFO = CreateObject("SAFRCFileDlg.FileOpen")
' exposed in safrcdlg.dll
oFO.OpenFileOpenDlg
wscript.echo oFO.FileName
 
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!

Thanks
 
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...
 
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.
Code:
set ocomdlg=createobject("mscomdlg.commondialog")
with ocomdlg
	.dialogtitle="select a file"
	.initdir="d:\test"
	.filter="All files (*.*)"
	.maxfilesize=10000	'filter filesize
	.showopen
end with
filespec=ocomdlg.filename
wscript.echo filespec
These two are the solution to get scripter by I would prefer.

regards - tsuji
 
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!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top