本文介绍了文件大小代码c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试编写一些文件大小为0 Kb的代码,然后发送电子邮件,我尝试了以下操作,但它不起作用?
我已附上代码能帮上什么忙吗?
Hi, I am trying to write some code that is the file size is = 0 Kb then send an email I have tried the following but it doesnt work?
I have attached the code can any one help?
if(new FileInfo(c:\test.txt)==0)
{
MailMessage oMsg = new MailMessage();
// TODO: Replace with sender e-mail address.
oMsg.From = "test@test.com";
// TODO: Replace with recipient e-mail address.
oMsg.To = "MyEmail@gmail.com";
oMsg.Subject = "Subject Line";
// SEND IN HTML FORMAT (comment this line to send plain text).
oMsg.BodyFormat = MailFormat.Html;
// HTML Body (remove HTML tags for plain text).
oMsg.Body = "<html><body>Body!</body></html>";
// ADD AN ATTACHMENT.
// TODO: Replace with path to attachment.
String sFile = @"C:\Test.txt";
MailAttachment oAttch = new MailAttachment(sFile, MailEncoding.Base64);
oMsg.Attachments.Add(oAttch);
// TODO: Replace with the name of your remote SMTP server.
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send(oMsg);
oMsg = null;
oAttch = null;
}
预先感谢您的任何帮助
Trot:confused:
Thanks in advance for any help
Trot:confused:
推荐答案
System.IO.FileInfo info = new System.IO.FileInfo(@"c:\test.txt");
if (info.Length == 0)
{
//shoot the email
}
不是简单的:)
simple isn''t :)
这篇关于文件大小代码c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!