Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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?

C#
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;
}

Thanks in advance for any help
Trot:confused:
Posted
Updated 24-Aug-10 23:28pm
v2
Comments
Sauro Viti 25-Aug-10 5:29am    
Use the PRE tags to enclose your code snippets: they make them more readable

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.
 
Share this answer
 
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 :)
 
Share this answer
 
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
 
Share this answer
 
Comments
senguptaamlan 28-Aug-10 2:28am    
didn't got Ur problem...please make it a bit more clear...and please don't make Ur comments as answers....make comments against answers....its creates confusion .... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900