ASP.Net - search sub folders in directory

lorena

Well-known member
Joined
Oct 23, 2003
Messages
134
Location
Phoenix, Arizona
I am trying to create a search page in VS 2003 that will search all of the subfolders in a directory. I had a way to do it in asp but .NET is different.
I tried this:
Code:
Dim strPath   As String = "/intranet/Quality/Discrepancy Reports Closed"
Dim strQuery  As String
Dim myDirInfo As DirectoryInfo
strQuery = txtQuery.Text
If strQuery = "" Then strQuery = CStr(Request.QueryString("query"))
  txtQuery.Text = strQuery
  myDirInfo = New DirectoryInfo(Server.MapPath(strPath))
  dgFiles.DataSource = myDirInfo.GetFiles("*" & strQuery & "*")   dgFiles.DataBind()
Any suggestions would be appreciated.
 
So I am a little dense here but what would a recursive search look like? I know what it looks like in asp but I am stumped as to how to convert it to .aspx
 
Well I dont know anything about asp, but heres what it looks like in vb if that helps.

Code:
     in main code body
    GetXMLFiles("c:\FolderNameHere")

    Private Sub GetFiles(ByVal path As String)

         search subdirectories
        For Each dir As String In System.IO.Directory.GetDirectories(path)
            GetFiles(dir)
        Next

         do something else here with files or directories
         as an example...
        For Each file As String In System.IO.Directory.GetFiles(path, "*.xml")
            ListBox1.Items.Add(file)
        Next

    End Sub
 
Back
Top