文件大小代码c# [英] File Size code c#

查看:73
本文介绍了文件大小代码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:

推荐答案

这会编译吗?您的路径不是用引号引起来的,我怀疑FileInfo是否可以与数字进行比较,尽管它具有可以使用的属性,并且您有大量的TODO也会阻止其工作.
This compiles ? Your path is not in quotes, I doubt a FileInfo can be compared to a number, although it will have properties that can be, and you have a ton of TODOs that will also stop it from working.


使用以下代码...

use the following code...

System.IO.FileInfo info = new System.IO.FileInfo(@"c:\test.txt");
        if (info.Length == 0)
        { 
            //shoot the email
        }



不是简单的:)



simple isn''t :)


感谢您的光临!

在另一个主题上,您可以使用通配符吗?如果我想从文件夹中附加* .txt,我也会遇到一些错误,是否必须使用搜索路径?

小跑
Thanks that works a treat!

On another topic, can you wild card? if I want to attahced *.txt from the folder I also get some errors do you have to use search paths?

Trot


这篇关于文件大小代码c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆