views:

28

answers:

3

Hi, i want to delete a file present in directory on the server. I have tried following code but code inside the file.exist never runs. It always skips it showing me that file does not exist. But file is present. can smone please help me. Thanx in advance

string filename = "Template\\copy.jpg";
        if(System.IO.File.Exists(filename))
        {
            System.IO.File.Delete(filename);
        }
+2  A: 

Try

string fileName = Server.MapPath(@"/Template/copy.jpg");
RandomNoob
it worked thanks a lot
pankaj
A: 

Maybe this will help.

madcapnmckay
+2  A: 
Should be like

string filename = Server.MapPath("~/Template/copy.jpg");
                System.IO.File.Delete(filename);
Muhammad Akhtar
You might need to call ResolveUrl on the "~/" path before passing that to Server.MapPath.
Zhaph - Ben Duguid