lorena Posted February 21, 2006 Posted February 21, 2006 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. Quote
lorena Posted February 21, 2006 Author Posted February 21, 2006 More Information sorry - the code I posted only searches the root folder and none of the subfolders. Quote
Cags Posted February 21, 2006 Posted February 21, 2006 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. Quote Anybody looking for a graduate programmer (Midlands, England)?
lorena Posted February 23, 2006 Author Posted February 23, 2006 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 Quote
Cags Posted February 24, 2006 Posted February 24, 2006 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 Quote Anybody looking for a graduate programmer (Midlands, England)?
lorena Posted February 24, 2006 Author Posted February 24, 2006 Thanks. That does help me to kind of see what I need to do Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.