Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hai all

i had implemented single word search....
now i need to work with multi word search...
i need to search files in server...

code for searching files using single word key is as follows:

string s = "", s1 = ""; //to get the file name
               // string files = "";
               string filename = "*" + tb_search.Text + "*";
               DirectoryInfo MyDir;
               ArrayList CellarList = new ArrayList();
               MyDir = new DirectoryInfo(Server.MapPath("files/"));
               string path = (Server.MapPath("files/"));
               //FileInfo[] MyFiles = MyDir.GetFiles("*.*");
               string[] fileList = System.IO.Directory.GetFiles(path, filename);

               foreach (string file in fileList)
               {
                   if (file.ToLower().Contains(tb_search.Text.ToLower().ToString()))
                   {
                       s = file.ToString();
                       s1 = s.Replace(path, "");
                       lb_search.Items.Add(s1);
                   }
               }



can any one help me...
thanks in advance
Posted
Updated 15-Jan-12 20:26pm
v3
Comments
Technoses 16-Jan-12 1:40am    
please tell us what do you want exactly
Ragi Gopi 16-Jan-12 1:52am    
i need to find files from my server using the key words...
now i had implemented it by searching with single word.......
now i need to seearch with multile keys as we do in google...

1 solution

As per your code, you are trying to search the file names in the given directory .,

for this you can use the below code.

string[] files = Directory.GetFiles(Server.MapPath("files/"), "*.*");

Second Argument can be any wild card.

Ex :
string[] files = Directory.GetFiles(Server.MapPath("files/"), "A*.*");
files start with "A"

string[] files = Directory.GetFiles(Server.MapPath("files/"), "ABC?.*");
Files Start with "ABC" and ends with any character.

string[] files = Directory.GetFiles(Server.MapPath("files/"), "ABC DEF*.*");
Files Start with "ABC DEF" and ends with any characters.

Hope this helps you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900