Ram Singh
Ram Singh

Reputation: 6918

How do I delete number of files from folder in asp.net?

i have a list of albums and photos in albums. Now i want when i delete a particular album then its photos also to be delete.The name for images of a particular album is like " if album's id is 1 so its images name should be 1_1,1_2,.. . So i have got the image name upto "1_" at the time of deletion of album. now i am confused how to delete the images which have prefix "1_". my code is

`For Each Alb_Id In Col_Alb_Ids
Dim imagefolder As String = ""
imagefolder = Server.MapPath("~/DesktopModules/Album/Images_Uploaded/")
Dim ss As String = Alb_Id & "_"
imagefolder.Contains(ss)
Dim aa As String = imagefolder + ss
If File.Exists(imagefolder.Contains(aa)) Then
  File.Delete(aa)
End If`

Upvotes: 0

Views: 683

Answers (2)

SUJEET
SUJEET

Reputation: 121

imagefolder.Contains(ss)

Dim aa As String = imagefolder + ss
If File.Exists(imagefolder.Contains(aa)) Then
      File.Delete(aa)
End If

Upvotes: 0

cjk
cjk

Reputation: 46425

You can call Directory.GetFiles passing in a wildcard for the search:

C# code

String[] albumFiles = Directory.GetFiles(imageFolder, ss + "*.*");

Upvotes: 1

Related Questions