Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7783837
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:57:30+00:00 2026-06-01T19:57:30+00:00

I’ve got an application that scan certain directories for any file which exceeds certain

  • 0

I’ve got an application that scan certain directories for any file which exceeds certain size. After it detects it, it will send a warning email, stating that certain files have reached certain size limits. My problem is my current program will send one email per file. Meaning if there is 10 file that is over limit, then it will will send 10 email. How to make it compile all of the file and send a list of those file in a single email?Here is my code if needed:

private void Form1_Load(object sender, EventArgs e)
    {
        count = 0;
        timer = new Timer();
        timer.Interval = 1000;
        timer.Tick += new EventHandler(timer1_Tick);
        timer.Start();


        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");
        ArrayList fileList = new ArrayList();      
        foreach(string s in s1)
        {   
            try
            {   
                FileInfo info = new FileInfo(s);
                FileSystemInfo sysInfo = new FileInfo(s);
                dr = dt.NewRow();
                //System.Collections.Generic.List<string> nameList;
                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)
                {
                    fileList.Add(sysInfo.Name);
                }

                if (dt.Rows.Count > 0)
                {
                    dataGridView1.DataSource = dt;
                }
            }
            catch (UnauthorizedAccessException ex)
            {
                MessageBox.Show("Error : " + ex.Message);
                continue;
            }

        }

        MessageBox.Show(fileList + "overlimit!!");

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:57:32+00:00Added an answer on June 1, 2026 at 7:57 pm

    Encapsulate the Mail options in a class
    with a public method/attribute that returns a boolean if one of the files meets the criteria and only perform the mail operations if the criteria are met:

    something like this — not checked as it was done on a mac in a text editor

    private void Form1_Load(object sender, EventArgs e)
    {
        count = 0;
        timer = new Timer();
        timer.Interval = 1000;
        timer.Tick += new EventHandler(timer1_Tick);
        timer.Start();
    
    
        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>());
    
        //s1 = Directory.GetFiles(@"F:\gdimaging\data", "*.*");
        dt.Columns.Add("File_Name");
        dt.Columns.Add("File_Type");
        dt.Columns.Add("File_Size");
        dt.Columns.Add("Create_Date");
        // new mail list class
        class mailList {
        public bool isEmpty = true;
        MailMessage mailMessage;
        // do all the onceonly stuff in the constructor
            public mailList(){
                mailMessage = new MailMessage();
                mailMessage.To.Add(new MailAddress("shahrul1509@yahoo.com"));
                mailMessage.To.Add(new MailAddress("shahrul_kakashi90@hotmail.com"));
        // set subject
                mailMessage.Subject = "FILE SIZE WARNING MESSAGE";
                // Identify the credentials to login to the gmail account  
                string sendEmailsFrom = "shahrul1509@gmail.com";
                        // password below is written in * to encrypt it
    
                string sendEmailsFromPassword = "***4556**";
                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.Credentials = cred;
                mailMessage.IsBodyHtml = true;
                mailMessage.From = new MailAddress("shahrul1509@gmail.com", "Shahrul Nizam");
    
            }
            public addFile(String fileName){
                mailMessage.Body = mailMessage.Body + sysInfo.Name+ "HAS REACH ITS SIZE LIMIT.";
                isEmpty = false;
            }
            public send(){
                mailClient.Send(mailMessage);
                MessageBox.Show("Email Notification Sent!");
            }
        }
    
        }
        try
            {
            mailList ml = new mailList();
            foreach(string s in s1)
                {
                    FileInfo info = new FileInfo(s);
                    FileSystemInfo sysInfo = new FileInfo(s);
                    dr = dt.NewRow();
                //System.Collections.Generic.List<string> nameList;
                    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)
                    {
                        ml.addFile(sysInfo.Name);
    
                        if (dt.Rows.Count > 0)
                        {
                        dataGridView1.DataSource = dt;
                        }
    
                    }
                    if(ml.isEmpty==false){
                        ml.Send();
                    }
                }
        catch (UnauthorizedAccessException ex)
        {
            MessageBox.Show("Error : " + ex.Message);
            continue;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I have a reasonable size flat file database of text documents mostly saved in
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.