Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Heey all

i am creating a system for for a webshop

and i have run into a little problem

i am using a detailsview to see my products

and now i need to delete a Product, the question is how do i delete the Image that are in a folder on my server??

my database look like:

ProductID
ProductName
ProductDesc
ProductPrice
ProductImage

"ProductImage" has the FilePath and ImageName to the image
Posted
Updated 29-Jan-13 2:38am
v3
Comments
ali_heidari_ 29-Jan-13 9:35am    
you want delete a file that ProductImage has its adress?
you can do it with system.io.file.delete then clear the productimage with a ado.net connecting!

C#
string path = "E:\\sasi\\delt.doc";
        FileInfo myfileinf = new FileInfo(path);
        myfileinf.Delete();



Make sure the ASP user has permissions to this folder. By default this user is not given access to much of the harddrive..
 
Share this answer
 
Use NameSpace: using System.IO;


File.Delete(Server.MapPath("~/ProductImage/" + ProductImage));


Remember: Product Image should be in format : image.jpg......
 
Share this answer
 
C#
if (System.IO.File.Exists(@"C:\test.txt"))
    System.IO.File.Delete(@"C:\test.txt"));


Try this
 
Share this answer
 

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