110,534
社区成员
发帖
与我相关
我的任务
分享
//读取附件的大小并返回字节大小
private long filelen(string s)
{
FileStream fs = File.OpenRead(s);
return fs.Length;
}
//添加附件时判断附件大小
private void ButtonAtt_Click(object sender, EventArgs e)
{
openFileDialog1.Multiselect = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
foreach (string s in openFileDialog1.FileNames)
{
AttLength = filelen(s);
if (AttLength <= 4194304)
{
AttsLength += AttLength;
myMail.Attachments.Add(AddAtt(s));
listBoxAtt.Items.Add(s);
}
else
{
MessageBox.Show("单个附件不能大于4M");
}
}
}
}