我在這裏有一個小問題。我有一個應用程序通過電子郵件發送一個文件列表名稱,通知用戶這些文件已超過一定的大小限制。但現在我希望它不僅發送文件名稱,而且還發送文件大小。我設法將文件大小附加到電子郵件。但我的問題是它展示的方式。我希望它顯示如下:通過電子郵件並排發送兩個列表?
THE FILES :
filename1 = filesize1
filename2 = filesize2
filename3 = filesize3
..
..
..
HAS REACHED ITS LIMITS!
但在電子郵件我目前的顯示格式是這樣的:
THE FILES :
filename1
filename2
filename3
filesize1
filesize2
filesize3
HAS REACHED ITS LIMITS!
現在我不知道如何來改變顯示格式,如第一個。任何幫助將不勝感激。 這裏是我的代碼片段:
private void Form1_Load(object sender, EventArgs e)
{
count = 0;
timer = new Timer();
timer.Interval = 1000;
timer.Tick += new EventHandler(timer1_Tick);
timer.Start();
System.Collections.Generic.List<string> files = new List<string>();
System.Collections.Generic.List<string> files1 = new List<string>();
//List<string> s1 = System.IO.Directory.GetFiles(@"C:\Documents and Settings\Administrator\Desktop\test", "*.*", SearchOption.AllDirectories).ToList<string>();
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");
foreach (string s in s1)
{
try
{
FileInfo info = new FileInfo(s);
FileSystemInfo sysInfo = new FileInfo(s);
dr = dt.NewRow();
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)
{
MyFiles = new Dictionary<string, string>();
//files.Add(sysInfo.Name.ToString());
//files1.Add(info.Length.ToString());
//arr = string.Join("<br/>", files.ToArray());
//arr1 = string.Join("<br/>", files1.ToArray());
MyFiles.Add(sysInfo.Name.ToString(), info.Length.ToString());
}
if (dt.Rows.Count > 0)
{
dataGridView1.DataSource = dt;
}
}
catch (UnauthorizedAccessException ex)
{
MessageBox.Show("Error : " + ex.Message);
continue;
}
}
if (arr != null)
{
///Basic Email message
MailMessage mailMessage = new MailMessage();
// Email to send to
mailMessage.To.Add(new MailAddress("[email protected]"));
mailMessage.To.Add(new MailAddress("[email protected]"));
//set subject
mailMessage.Subject = "FILE SIZE WARNING MESSAGE";
//set body
//mailMessage.Body = "THE FILES : <br/><br/>" + arr + arr1 + "<br/><br/> HAS REACH ITS SIZE LIMIT!!";
mailMessage.Body = "THE FILES : <br/><br/>";
foreach (string key in MyFiles.Keys)
{
mailMessage.Body += key + " = " + MyFiles[key] + "<br/>";
mailMessage.Body += "<br/> HAS REACHED ITS SIZE LIMIT!";
}
mailMessage.IsBodyHtml = true;
mailMessage.From = new MailAddress("************", "Shahrul Nizam");
//Identify the credentials to login to the gmail account
string sendEmailsFrom = "**********";
string sendEmailsFromPassword = "**********";
NetworkCredential cred = new NetworkCredential(sendEmailsFrom, sendEmailsFromPassword);
SmtpClient mailClient = new SmtpClient("smtp.gmail.com", 587);
mailClient.EnableSsl = true;
mailClient.DeliveryMethod = SmtpDeliveryMethod.Network;
mailClient.UseDefaultCredentials = false;
//mailClient.Timeout = 20000;
mailClient.UseDefaultCredentials = true;
mailClient.Credentials = cred;
mailClient.Send(mailMessage);
//MessageBox.Show("Email Notification Sent!");
//MessageBox.Show(fileList.ToString() + "overlimit!!");
}
}
private void timer1_Tick(object sender, EventArgs e)
{
count++;
if (count == 600)
{
count = 0;
timer.Stop();
Application.Restart();
}
}
你目前如何生成太大的文件列表? – sarnold 2012-04-20 02:30:52
你走了。今晚我想不出更完整的答案,爲時已晚。請注意,如果有幫助,給予接受的答案是一個好主意 - >它會提高你的速度,而更多的人(很可能比我更好)會傾向於回答:) – 2012-04-20 02:51:09