The right way to get the folder within an ASP.NET application is to use MapPath
You may need to adjust this a bit as this was from a console app, and just had the FolderPath redeclared.
string FolderPath = Server.MapPath("\XML");
DirectoryInfo dir = new DirectoryInfo(FolderPath);
try {
foreach (FileInfo fi in dir.GetFiles()) {
fi.Delete();
}
}
catch (Exception ex) {
MessageBox.Show(ex.Message);
}