Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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:

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.

Posted
You need to make a recursive loop to search all folders. So for each directory in a directory you call SearchFiles passing in the directory path.
Anybody looking for a graduate programmer (Midlands, England)?
Posted
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
Posted

Well I don't know anything about asp, but heres what it looks like in vb if that helps.

 

   ' 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

Anybody looking for a graduate programmer (Midlands, England)?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...