Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
2.60/5 (2 votes)
See more:
HI ALL ,

I have uploaded images in the folder "uploaded",and i want to remove a certain image when the user wants.So how to remove an image that is uploaded in a folder ?

Thanks in advance.
Posted

string imageFilePath = Serve.MapPath(@"~/uploaded/imagefilename.extension");
System.IO.File.Delete("imageFilePath");


Simple isn't ?? :)
 
Share this answer
 
File/Image Updation or delete it using C#.Net , Asp.Net

C#
        //      FILE OR IMAGE DELETION AND CREATION ( Use for delete the Image) (UPDATING
// THE PREVIOUS FILE using c#.net , asp.net


using System.Drawing;
using System.IO;


public void filedel()         
    {
        string path = Server.MapPath(@"images\");
        string imgurl = path + "a.jpg";
        try
        {
            FileInfo TheFile = new FileInfo(imgurl);
            if (TheFile.Exists)
            {
                File.Delete(imgurl);   // It not works if file is used in another process
            }
            else
            {
               // File.Create(imgurl);  
            //or
            // Code To Create image
            Bitmap bmp = new Bitmap(2, 2);
            bmp.Save(imgurl, System.Drawing.Imaging.ImageFormat.Jpeg);
            bmp.Dispose();
            }
            Label1.Text = "Sucess";
        }
        catch (Exception ex)
        {
            Label1.Text = ex.Message;
        }
    }


Thank You
Solution Source : Source of above code & Detail Description[^]
 
Share this answer
 
v3
Comments
Sandeep Mewara 14-Oct-12 2:30am    
Why opening so old threads that too suitable answers are there (few even marked as solved!). Please avoid so.
Hemant Singh Rautela 14-Oct-12 2:32am    
but when i see i saw only question no any answer is there...

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