Click here to Skip to main content
15,891,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to delete a image file from my project
i do this code but don,t delete
i have a images folder
in this folder is a image
my image name is :"2.jpg"
String patha = "~\\images\\2.jpg"

if (System.IO.File.Exists(patha))
{
System.IO.File.Delete(patha)
}

dont run file.delete(patha) when run my project
Posted
Updated 14-Jul-12 8:32am
v3
Comments
[no name] 14-Jul-12 11:39am    
Maybe you should check your path.
Abdul Quader Mamun 14-Jul-12 11:39am    
Edited for code block

Use this code

C#
String patha= String.Format(@"{0}\{1}" ,Server.MapPath("images"),"2.jpg");
 
            if (System.IO.File.Exists(patha))
            {
                System.IO.File.Delete(patha);
            }



Thanks,
Mamun
 
Share this answer
 
Comments
Abdul Quader Mamun 14-Jul-12 11:52am    
Is this work fine for you. then don't be late to voting me and accept answer.
patha is not physical path.
String patha= Server.MapPath("~/images/2.jpg");
try it,
 
Share this answer
 
Comments
Member 4634921 27-Mar-13 3:08am    
This code will use only to delete specific image, as this is a hard coded, what if i want to delete selected image from the folder without using database?? please help.
XML
hello

used this
<pre>  string path = Server.MapPath("~/images") + "\\" + 2.jpg;

                    if (File.Exists(path))
                    {
                        System.IO.File.Delete(path);
}


this would work fine  because i alkways used it in my live project





<b>if my ans is not gives any help you please give me comments</b></pre>
 
Share this answer
 
Comments
Member 4634921 27-Mar-13 3:09am    
This code will use only to delete specific image, as this is a hard coded, what if i want to delete selected image from the folder without using database?? please help.
rizwan muhammed khan gouri 6-Apr-13 5:40am    
hello
Please make function that will pass your image url and call it simple.

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