Click here to Skip to main content
15,947,411 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,

I had implemented single word search, now I need to work with multiple key-word search..
I need to search files in server...

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

C#
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 21:23pm
v2

1 solution

Look at this it may help you:


http://www.asp.net/web-pages/tutorials/files,-images,-and-media/working-with-files[^]



Reading Files in ASP and How to Search for a particular text in all files in a specific directory.[^]











=================================================================
try this:


XML
.aspx file

    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:ListBox ID="ListBox1" runat="server"></asp:ListBox>

.cs file

  protected void Button1_Click(object sender, EventArgs e)
    {
        ListBox1.Items.Clear();
        DirSearch("c:\\test");
    }
    void DirSearch(string sDir)
    {
        foreach (string d in Directory.GetDirectories(sDir))
        {
            foreach (string f in Directory.GetFiles(d, TextBox1.Text))
            {
                ListBox1.Items.Add(f);//if find the file, then put it into the listbox

            }
            DirSearch(d);
        }
    }


try this link also:

http://www.4guysfromrolla.com/articles/052803-1.aspx[^]
 
Share this answer
 
v4
Comments
Emad Al Hawary 16-Jan-12 3:31am    
http://www.developerfusion.com/code/4359/listing-files-folders-in-a-directory/
Ragi Gopi 16-Jan-12 3:44am    
am not asking about how to list files......

i want to know how to search files...as per the key word in the textbox...

that is now i am extracting files by one key word ..now i need to use multile key word search as in google......(but from my server)

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