Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi all :)

I have images at a folder

and I want to update database and delete the old image

how can I do it ?



thank you all :)
Posted
Comments
phil.o 31-Oct-11 17:11pm    
What did you try ?

What's the problem, System.IO.File.Delete? Here: http://msdn.microsoft.com/en-us/library/system.io.file.delete.aspx[^]. Keep in sync with the database where you store the file names.

—SA
 
Share this answer
 
v2
Comments
Espen Harlinn 31-Oct-11 17:16pm    
My 5 - simple and elegant :)
Sergey Alexandrovich Kryukov 31-Oct-11 17:20pm    
Thank you, Espen.
--SA
Find the file in and if it exist then delete it as:
C#
filename= AppDomain.CurrentDomain.BaseDirectory + "/images/Photos/" + file;
if (File.Exists(filename))
                           File.Delete(filename);
 
Share this answer
 
C#
System.IO.File.Delete(filepath);
 
Share this answer
 
try this
C#
DirectoryInfo di = new DirectoryInfo("c:/inetpub/root/Images");
FileInfo[] rgFiles = di.GetFiles("*.aspx");
foreach(FileInfo fi in rgFiles)
{
 File.Delete(fi);// Delete the files here
}
 
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