Browse For File Dialog in Vista

Author Message
TNO

  • Total Posts : 2094
  • Scores: 36
  • Reward points : 0
  • Joined: 12/18/2004
  • Location: Earth
  • Status: offline
Browse For File Dialog in Vista Thursday, September 16, 2010 10:30 PM (permalink)
4.67
I had insomnia last night, so I wrote a function to resolve the dreaded file dialog issue in Windows Vista and Windows 7:

 Function BrowseForFile()
 Dim shell : Set shell = CreateObject("WScript.Shell")
 Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
 Dim tempFolder : Set tempFolder = fso.GetSpecialFolder(2)
 Dim tempName : tempName = fso.GetTempName()
 Dim tempFile : Set tempFile = tempFolder.CreateTextFile(tempName & ".hta")
 tempFile.Write _
 "<html>" & _
 "    <head>" & _
 "        <title>Browse</title>" & _
 "    </head>" & _
 "    <body>" & _
 "        <input type='file' id='f'>" & _
 "        <script type='text/javascript'>" & _
 "            var f = document.getElementById('f');" & _
 "            f.click();" & _
 "            var shell = new ActiveXObject('WScript.Shell');" & _
 "            shell.RegWrite('HKEY_CURRENT_USER\\Volatile Environment\\MsgResp', f.value);" & _
 "            window.close();" & _
 "        </script>" & _
 "    </body>" & _
 "</html>"
 tempFile.Close

 shell.Run tempFolder & "\" & tempName & ".hta", 1, True

 BrowseForFile = shell.RegRead("HKEY_CURRENT_USER\Volatile Environment\MsgResp")
 shell.RegDelete "HKEY_CURRENT_USER\Volatile Environment\MsgResp"
End Function

MsgBox BrowseForFile 


Feedback is welcome of course.
<message edited by TNO on Tuesday, October 26, 2010 12:16 PM>
To iterate is human, to recurse divine. -- L. Peter Deutsch
 
#1
    TNO

    • Total Posts : 2094
    • Scores: 36
    • Reward points : 0
    • Joined: 12/18/2004
    • Location: Earth
    • Status: offline
    Re:Browse For File Dialog in Vista Tuesday, October 26, 2010 12:17 PM (permalink)
    0
    Hooray, the forum is "fixed".  Code copied from pastebin...
    To iterate is human, to recurse divine. -- L. Peter Deutsch
     
    #2
      jloyzaga

      • Total Posts : 77
      • Scores: 0
      • Reward points : 0
      • Joined: 9/24/2007
      • Status: offline
      Re:Browse For File Dialog in Vista Friday, May 06, 2011 7:03 PM (permalink)
      0
      so that looks for a *.hta set of files? how can I get all .xls files?
      tried changing .hta to xls and it couldn't find any? is it because it looks for it only in the c:\programfile\vbsedit folder?
       
      #3
        TNO

        • Total Posts : 2094
        • Scores: 36
        • Reward points : 0
        • Joined: 12/18/2004
        • Location: Earth
        • Status: offline
        Re:Browse For File Dialog in Vista Friday, May 06, 2011 8:02 PM (permalink)
        0
        No, it opens a browse dialog using an hta file to bypass the browser's security. There is no native filter for the file type. All files are browsed for as is done normally through Windows Explorer
        To iterate is human, to recurse divine. -- L. Peter Deutsch
         
        #4
          jloyzaga

          • Total Posts : 77
          • Scores: 0
          • Reward points : 0
          • Joined: 9/24/2007
          • Status: offline
          Re:Browse For File Dialog in Vista Saturday, May 07, 2011 8:38 AM (permalink)
          0
          so why is it only showing the files in the native vbsedit directory?" how can I filter it and run against a specific folder?
           
          #5
            TNO

            • Total Posts : 2094
            • Scores: 36
            • Reward points : 0
            • Joined: 12/18/2004
            • Location: Earth
            • Status: offline
            Re:Browse For File Dialog in Vista Saturday, May 07, 2011 10:57 AM (permalink)
            0
            If you run the file from the desktop, it'll open a dialog from there. If you run it from c:\, the dialog will display from there.
             
            Using this approach you are at the mercy of what the behavior <input type="file"> supports:
             
            http://msdn.microsoft.com...5263%28v=vs.85%29.aspx
            To iterate is human, to recurse divine. -- L. Peter Deutsch
             
            #6
              mogoo

              • Total Posts : 2
              • Scores: 0
              • Reward points : 0
              • Joined: 2/24/2012
              • Location: Calif
              • Status: offline
              Re:Browse For File Dialog in Vista Friday, February 24, 2012 10:16 AM (permalink)
              0
              TNO - thank you for this excellent script.
               
              I noticed that running this returns the mapped drive path.
               
              Since I've no real experience with HTA how could this be modified to return the UNC path and file name?
               
              tia
               
              #7
                TNO

                • Total Posts : 2094
                • Scores: 36
                • Reward points : 0
                • Joined: 12/18/2004
                • Location: Earth
                • Status: offline
                Re:Browse For File Dialog in Vista Friday, February 24, 2012 5:58 PM (permalink)
                0
                mogoo


                TNO - thank you for this excellent script.

                I noticed that running this returns the mapped drive path.

                Since I've no real experience with HTA how could this be modified to return the UNC path and file name?

                tia

                 
                Just browse through the "Network" folder instead of the drive
                To iterate is human, to recurse divine. -- L. Peter Deutsch
                 
                #8
                  mogoo

                  • Total Posts : 2
                  • Scores: 0
                  • Reward points : 0
                  • Joined: 2/24/2012
                  • Location: Calif
                  • Status: offline
                  Re:Browse For File Dialog in Vista Saturday, February 25, 2012 7:13 AM (permalink)
                  0
                  Thank you - once I added "Network" to the Favorite Links in Windows Explorer worked like a charm!
                   
                  Appreciate it!
                   
                  #9

                    Online Bookmarks Sharing: Share/Bookmark

                    Jump to:

                    Current active users

                    There are 0 members and 1 guests.

                    Icon Legend and Permission

                    • New Messages
                    • No New Messages
                    • Hot Topic w/ New Messages
                    • Hot Topic w/o New Messages
                    • Locked w/ New Messages
                    • Locked w/o New Messages
                    • Read Message
                    • Post New Thread
                    • Reply to message
                    • Post New Poll
                    • Submit Vote
                    • Post reward post
                    • Delete my own posts
                    • Delete my own threads
                    • Rate post

                    2000-2012 ASPPlayground.NET Forum Version 3.9