Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
There is a List view for images in my .aspx page, I want to delete selected image from the folder without using database as my site is static and i have not used database, how can i delete selected image from the folder? please help.
Posted

Do something like this :-

C#
string FileName ="test.txt";
string Path = "E:\\" + FileName;
FileInfo file = new FileInfo(Path);
if (file.Exists)
{
  file.Delete();
}


Get your file name from listview and then find the path then delete.
And do remember to include using System.IO; namespace.
So simple Isn't it?

Or

C#
File.Delete(Server.MapPath(@"Images\SomeImage.png"));


here you can get your image name from list view.

Happy Holi.
 
Share this answer
 
v2
Comments
Member 12809622 22-Dec-16 5:38am    
Hi there, I am using the same code of yours but fileinfo's variable file is null ? why is the file not coming /what is the error ?
datatable dt=selecet postid from postdetails

var a= dt.rows.count;

var i;
for(I=0;I<a;i++)>
{
datatable dt1=select imagepath from image where postid=dt[i][0]
var b=dt1.rows.count;
for(j=0;j<b;j++)>
{
var temp=dt1[j][0];
dlete(temp);
}
 
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