How to open a GetFilename dialog box 
Author Message
 How to open a GetFilename dialog box

I would like to open the standard window box that allows the users to
select a file name and browse thru directories from VBScript...

Any exemple would be welcome
Thanks in advance.



Mon, 28 Apr 2003 03:00:00 GMT  
 How to open a GetFilename dialog box

Quote:

> I would like to open the standard window box that allows the users to
> select a file name and browse thru directories from VbScript...

> Any exemple would be welcome
> Thanks in advance.

In an ASP or stand alone VBS script?

In ASP, simply use a 'files' control ...

document.WriteLn("<input id=""file1"" type=""file"">")

I think, but I am no ASP programmer.

In a stand alone script, you need a 'console' into/from which a control
can be written/accessed.  A very common solution is to use IE as the
console.  The following is my most recent effort that uses IE ...

' Adapted from an example by Walter Zachery
wsh.echo BrowseForFile("Make a selection", "C:\*.*")

Function BrowseForFile(Prompt, StartAtLocation)
  With CreateObject("InternetExplorer.Application")
    .Visible = True
    .Height = 200 : .Width = 400 : .Top = 200 : .Left = 200
    .ToolBar = False : .StatusBar = False
    .RegisterAsDropTarget = False
    .Navigate("about:blank")
    While .Busy
      If WScript.Version > 5 Then WScript.Sleep(100)
    Wend
    With .document
      .WriteLn("<html><body bgcolor=""Silver""><form><br><br><center>")
      .WriteLn("<input id=""file"" type=""file"" style=""Width:80%"">")
      .WriteLn("<input type=""button"" " & _
               "value=""Click here to submit file name""" & _
               "onclick=""document.title='Done'"">")
      .WriteLn("</center></form></body></html>")
      .title= Prompt & " " & string(255, ".  ")
      .all.file.focus
      If WScript.Version > 5 Then
        With CreateObject("Wscript.Shell")
          .SendKeys StartAtLocation
          WSH.Sleep 100
          .SendKeys "{Tab} " ' Opens dialog window at StartLocation
        End With
      End if
      On Error Resume Next
      Do While not .title = "Done"
        if Err.Number <> 0 Then Exit Do
        If WScript.Version > 5 Then WScript.Sleep 200
      Loop
      BrowseForFile = .all.file.value
    End With
    .Visible = False
  End With
End Function

The navigation to a starting location requires WSH v2 (aka 5.1).
Otherwise, the file browsing always starts at the Desktop.

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/



Mon, 28 Apr 2003 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Open Multiselect Open dialog box

2. Centering a Open Dialog box using the Common dialog

3. How to just open the Open dialog box?

4. File Open Dialog box from CmnDlg32.dll?

5. WSH and "Open File" dialog box

6. Open file dialog box and upload file

7. Bypass Open/Download Dialog Box

8. open common dialog box

9. invoke the Open file dialog box in DHTML

10. Opening a dialog box inside of a webpage.

11. invoke the Open file dialog box in DHTML

12. Open File Dialog Box

 

 
Powered by phpBB® Forum Software