A
FileStream
is used for reading the contents of a file, not for listing the files in a folder.
You can't delete a file whilst you've got an open
FileStream
referencing it.
If you're trying to delete all matching files in a specific folder, you need to use
Directory.GetFiles[
^]:
string folder = Server.MapPath("~/Pictures/");
foreach (string file in Directory.GetFiles(folder, "*.jpg"))
{
try
{
File.Delete(file);
}
catch (IOException ex)
{
Label100.Text = string.Format("Delete '{0}': {1}", Path.GetFileName(file), ex);
}
}