我有一个应用程序可以扫描某些目录以查找任何超过特定大小的文件。检测到它后,它会发送一封警告电子邮件,说明某些文件已达到一定的大小限制。我的问题是我当前的程序将为每个文件发送一封电子邮件。这意味着如果有 10 个文件超出限制,那么它将发送 10 封电子邮件。如何使它编译所有文件并在一封电子邮件中发送这些文件的列表?如果需要,这是我的代码:
private void Form1_Load(object sender, EventArgs e)
{
count = 0;
timer = new Timer();
timer.Interval = 1000;
timer.Tick += new EventHandler(timer1_Tick);
timer.Start();
List<string> s1 = System.IO.Directory.GetFiles(@"F:\gdimaging\data", "*.*", SearchOption.AllDirectories).ToList<string>();
s1.AddRange(System.IO.Directory.GetFiles(@"F:\hios\DATA", "*.*", SearchOption.AllDirectories).ToList<string>());
s1.AddRange(System.IO.Directory.GetFiles(@"F:\imgviewer\data", "*.*", SearchOption.AllDirectories).ToList<string>());
s1.AddRange(System.IO.Directory.GetFiles(@"F:\newcnas\data", "*.*", SearchOption.AllDirectories).ToList<string>());
s1.AddRange(System.IO.Directory.GetFiles(@"F:\newpod\data", "*.*", SearchOption.AllDirectories).ToList<string>());
s1.AddRange(System.IO.Directory.GetFiles(@"F:\OMS\data", "*.*", SearchOption.AllDirectories).ToList<string>());
s1.AddRange(System.IO.Directory.GetFiles(@"F:\WEBIMG", "*.*", SearchOption.AllDirectories).ToList<string>());
dt.Columns.Add("File_Name");
dt.Columns.Add("File_Type");
dt.Columns.Add("File_Size");
dt.Columns.Add("Create_Date");
ArrayList fileList = new ArrayList();
foreach(string s in s1)
{
try
{
FileInfo info = new FileInfo(s);
FileSystemInfo sysInfo = new FileInfo(s);
dr = dt.NewRow();
//System.Collections.Generic.List<string> nameList;
dr["File_Name"] = sysInfo.Name;
dr["File_Type"] = sysInfo.Extension;
dr["File_Size"] = (info.Length / 1024).ToString();
dr["Create_Date"] = sysInfo.CreationTime.Date.ToString("dd/MM/yyyy");
dt.Rows.Add(dr);
if ((info.Length / 1024) > 1500000)
{
fileList.Add(sysInfo.Name);
}
if (dt.Rows.Count > 0)
{
dataGridView1.DataSource = dt;
}
}
catch (UnauthorizedAccessException ex)
{
MessageBox.Show("Error : " + ex.Message);
continue;
}
}
MessageBox.Show(fileList + "overlimit!!");
}