Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
FileInfo file = new FileInfo(Session["Path"].ToString());
       if (file.Exists)
       {
           file.Delete();

       }



by using this code i m able to delete only one file from the document. i need to delete the files of particular employeeid.
VB
example:
101_resume.pdf,
102_voter.pdf,
 i m able to delete the first. how to go with second also. at a time they need to delete
Posted
Updated 12-Apr-13 23:04pm
v2

try this code as per ur requirements
C#
FileInfo file = new FileInfo(Server.MapPath("foldername\\filename"));
        if (file.Exists)
        {
            File.Delete(Server.MapPath("foldername\\filename"));

        }
 
Share this answer
 
Comments
Dhritirao's 13-Apr-13 5:04am    
as per this code i m able to delete the first document of the employee then how to delete other ?
Pallavi Waikar 13-Apr-13 5:17am    
if these file name are from database...
then try
while (dr.Read())
{
FileInfo file = new FileInfo(Server.MapPath("deletedemo\\" + dr["filename"].ToString()));
if (file.Exists)
{
File.Delete(Server.MapPath("deletedemo\\" + dr["filename"].ToString()));

}
}
if you are using seperate folder foreach employee. then try this.
C#
private static void EmployeeFiles(string EmployeeFolderPath)
        {
            try
            {
                if (Directory.Exists(EmployeeFolderPath))
                {
                    foreach (var item in Directory.GetFiles(EmployeeFolderPath))
                    {
                        if (File.Exists(item))
                        {
                            File.Delete(item);
                        }
                    }
                }
            }
            catch (Exception)
            {
                
                throw;
            }
        }
 
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