How to delete (Particular) files in ASP .NET and in C# Example/Sample code

How to delete (Particular) files in ASP .NET and in C# Example/Sample code

ASP.NET and C# sample Code:



//Sample code to delete PDF files
static void DeletePDFFiles()
        {
            string strPath = “<Pathe of the directory>”;
            DirectoryInfo dir = new DirectoryInfo(strPath);

            foreach (FileInfo flInfo in dir.GetFiles())
            {
                String strExtenstion = Path.GetExtension(flInfo.Name);

                if (strExtenstion.ToLower().Equals(".pdf"))
                {
                       flInfo.Delete();
                }
            }
        }

No comments:

Post a Comment