Results 1 to 7 of 7

Thread: Using a webbrowser control as a file browser

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662

    Using a webbrowser control as a file browser

    Somebody mentioned to me that you could use the webbrowser control to browse for files. Setting the URL parameter to a local folder does this.

    Now, does anybody know how to do anything with it, such as get the currently selected file(s)/folder(s), override the default double-click action (like open and save as windows do), and change the view style (details vs. large icon)?

  2. #2
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: Using a webbrowser control as a file browser

    Here is how you change the view style.

    vb.net Code:
    1. Imports System.Runtime.InteropServices
    2. Imports System.Text
    3.  
    4. Public Class Form1
    5.  
    6.     Private Const LV_VIEW_ICON As Integer = &H0
    7.     Private Const LV_VIEW_DETAILS As Integer = &H1
    8.     Private Const LV_VIEW_SMALLICON As Integer = &H2
    9.     Private Const LV_VIEW_LIST As Integer = &H3
    10.     Private Const LV_VIEW_TILE As Integer = &H4
    11.     Private Const EM_HIDEBALLOONTIP As Integer = &H1504
    12.     Private Const LVM_SETVIEW As Integer = &H108E
    13.  
    14.     Private Const ListViewClassName As String = "SysListView32"
    15.     Private Shared ReadOnly NullHandleRef As HandleRef = New HandleRef(Nothing, IntPtr.Zero)
    16.  
    17.     <DllImport("user32.dll", ExactSpelling:=True)> _
    18.     Private Shared Function EnumChildWindows( _
    19.         ByVal hwndParent As HandleRef, _
    20.         ByVal lpEnumFunc As EnumChildrenCallback, _
    21.         ByVal lParam As HandleRef _
    22.     ) As Boolean
    23.     End Function
    24.  
    25.     <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    26.     Private Shared Function SendMessage( _
    27.         ByVal hWnd As HandleRef, _
    28.         ByVal Msg As UInteger, _
    29.         ByVal wParam As Integer, _
    30.         ByVal lParam As Integer _
    31.     ) As Integer
    32.     End Function
    33.  
    34.     <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
    35.     Private Shared Function RealGetWindowClass( _
    36.         ByVal hwnd As IntPtr, _
    37.         <Out()> ByVal pszType As StringBuilder, _
    38.         ByVal cchType As UInteger _
    39.     ) As UInteger
    40.     End Function
    41.  
    42.     Private Delegate Function EnumChildrenCallback( _
    43.         ByVal hwnd As IntPtr, _
    44.         ByVal lParam As IntPtr _
    45.     ) As Boolean
    46.     Private listViewHandle As HandleRef
    47.  
    48.     Private Sub FindListViewHandle()
    49.         Me.listViewHandle = NullHandleRef
    50.         Dim lpEnumFunc As EnumChildrenCallback = New EnumChildrenCallback(AddressOf EnumChildren)
    51.         EnumChildWindows(New HandleRef(Me.WebBrowser1, Me.WebBrowser1.Handle), lpEnumFunc, NullHandleRef)
    52.     End Sub
    53.  
    54.     Private Function EnumChildren( _
    55.         ByVal hwnd As IntPtr, _
    56.         ByVal lparam As IntPtr _
    57.     ) As Boolean
    58.  
    59.         Dim sb As StringBuilder = New StringBuilder(100)
    60.         RealGetWindowClass(hwnd, sb, 100)
    61.         If sb.ToString() = ListViewClassName Then
    62.             Me.listViewHandle = New HandleRef(Nothing, hwnd)
    63.         End If
    64.         Return True
    65.     End Function
    66.  
    67.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    68.         WebBrowser1.Navigate("c:\")
    69.     End Sub
    70.  
    71.     Private Sub Button1_Click( _
    72.         ByVal sender As System.Object, _
    73.         ByVal e As System.EventArgs _
    74.     ) Handles Button1.Click
    75.  
    76.         Dim view As Integer
    77.         FindListViewHandle()
    78.         view = LV_VIEW_ICON
    79.         SendMessage(Me.listViewHandle, LVM_SETVIEW, view, 0)
    80.     End Sub
    81.  
    82. End Class

  3. #3
    Lively Member
    Join Date
    May 2008
    Posts
    117

    Re: Using a webbrowser control as a file browser

    Hi!

    I've done a complete Filebrowser, based on that.
    On ActiveVB-Upload u can search for "filebrowser".

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jun 1999
    Location
    California, USA
    Posts
    662

    Re: Using a webbrowser control as a file browser

    Quote Originally Posted by Nerd44
    Hi!

    I've done a complete Filebrowser, based on that.
    On ActiveVB-Upload u can search for "filebrowser".
    Thank you very much for this, but I have one question first. I'm not at my development machine right now so I can't test this. Are properties provided for changing the view and/or allowing to filter files on a wildcard?

    Quote Originally Posted by Deepak Sakpal
    Here is how you change the view style.
    Thanks for the code. I'll take a look at this when I can.

    I'm still looking to see if there's another way to do this. I've posted a more broad question on this at http://www.vbforums.com/showthread.php?t=526311

  5. #5
    Lively Member
    Join Date
    May 2008
    Posts
    117

    Re: Using a webbrowser control as a file browser

    Are properties provided for changing the view and/or allowing to filter files on a wildcard?
    sorry, no.

  6. #6
    New Member
    Join Date
    Apr 2011
    Posts
    1

    Re: Using a webbrowser control as a file browser

    I am preforming a file copy when my form loads, and then trying to navigate to that local location, and then change my view.. When performing the file copy first, the view change does not sick.. Any ideas?

  7. #7
    Lively Member Amerigo's Avatar
    Join Date
    Dec 2008
    Location
    PSR B1620-26 c-1
    Posts
    126

    Re: Using a webbrowser control as a file browser

    @ Deepak Sakpal... Can you provide similar coding to change sorting and grouping. All the above and sorting and grouping can be done with the context menu, but I want my app to load with directory contents automatically sorted by type.
    Anyone who does not wonder, is either omnipotent or a fool.
    Amerigoware <<<My Projects

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width