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

i need to search files like, pdf,doc,jpg etc in a server where my site is hosted. i am now developing a website that is to be hosted and used in intranet. i am now working in file system.

my actual problem is i don't know how to represent the server through program , that is, don't know how to set the path to upload the files to server.

can any on help me with code for the above..


i tried the following code:-
C#
protected void Button1_Click(object sender, EventArgs e)
   {
       string filename = TextBox1.Text;
       if (File.Exists(Server.MapPath("testit" + ( filename))))

      // if (File.Exists(Server.MapPath(filename)))
       {
           Response.Write("file exist");
       }
       else
       {
           Response.Write("no");
       }
   }


testit is the virtual directory that i made for hosting my website in IIS


thanks in advance.....

Solution in my previous question is not working any one plz help me
Posted
Updated 5-Dec-11 23:45pm
v3
Comments
Anuj Banka 6-Dec-11 5:43am    
If you have some code then please show us.then we can help you better.

C#
//string filename = TextBox1.Text;
 if (File.Exists(Server.MapPath("Image/untitled.png")))
     // if (File.Exists(Server.MapPath(filename)))

     Response.Write("file exist");
 else
 {
     Response.Write("no");
 }



here "Image" is folder in solution and "untitled.png" is file in this folder and i am able to get this. I think in text box you are not getting correct file path.
 
Share this answer
 
Comments
Ragi Gopi 6-Dec-11 5:57am    
thanks dear...
it works
Anuj Banka 6-Dec-11 6:00am    
Welcome
Ragi Gopi 6-Dec-11 6:17am    
how can i display that file in my page for download???which control i should use for that
Ragi Gopi 6-Dec-11 6:17am    
can u plz help
Ragi Gopi 7-Dec-11 5:41am    
can u do me a favor .....
sorry for disturbing u...




i need to display list of files from remote server which has the keyword i specify in a textbox. and also need to see that file when double cliked on it.
which control should i use to display the list...if i use listbox, i think there is no double click event.
i tried your code :-

string filename = TextBox1.Text;
if (File.Exists(Server.MapPath("files/" + (filename))))
{
Response.Write("file exist");
ListBox1.Items.Add(filename);

}
else
{
Response.Write("no");
}

here file is the folder name,
the above shows only single file, and it is displayed only when the complete name is inputed.


can you plz help me...
thanks in advance...
You can try this code to search files in the directory:

public static void disp(string source)
    {

        DirectoryInfo dr = new DirectoryInfo(source);

        DirectoryInfo dir = new DirectoryInfo(des);

        foreach (FileInfo fs in dr.GetFiles())
        {

            path = fs.Extension;

            switch (path)
            {

                case ".doc":

                    if (!Directory.Exists("DOC"))
                    {

                        dir.CreateSubdirectory("DOC");

                    }



                    Console.WriteLine("file" + fs.Name);

                   

                    break;

                case ".txt":

                    if (!Directory.Exists("txt"))
                    {

                        dir.CreateSubdirectory("txt");

                    }



                    Console.WriteLine("file" + fs.Name);

                    

                    break;

                case ".pdf":

                    if (!Directory.Exists("txt"))
                    {

                        dir.CreateSubdirectory("txt");

                    }



                    Console.WriteLine("file" + fs.Name);

                    

                    break;

            }



        }
    }
 
Share this answer
 
v2

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