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 7829461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:46:25+00:00 2026-06-02T10:46:25+00:00

I have a little problem here. I got an application which sends a list

  • 0

I have a little problem here. I got an application which sends a list of files name through email notifying the user that those files has exceeded a certain size limit. But now I want it to not only send the files name but also the files size. I manage to attach the file size to the email. But my problem is the way it displayed. I want it to displayed like :

THE FILES :

filename1 = filesize1
filename2 = filesize2
filename3 = filesize3
..
..
..

HAS REACHED ITS LIMITS!

But my current display format in the email is like :

THE FILES :

filename1
filename2
filename3
filesize1
filesize2
filesize3

HAS REACHED ITS LIMITS!

And now I don’t know how to change the display format like the first one. Any help would be greatly appreciated.
Here is my code snippet :

private void Form1_Load(object sender, EventArgs e)
    {   
        count = 0;
        timer = new Timer();
        timer.Interval = 1000;
        timer.Tick += new EventHandler(timer1_Tick);
        timer.Start();
        System.Collections.Generic.List<string> files = new List<string>();
        System.Collections.Generic.List<string> files1 = new List<string>();
        //List<string> s1 = System.IO.Directory.GetFiles(@"C:\Documents and Settings\Administrator\Desktop\test", "*.*", SearchOption.AllDirectories).ToList<string>();
        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");

        foreach (string s in s1) 
        {   
            try
            {   
                FileInfo info = new FileInfo(s);
                FileSystemInfo sysInfo = new FileInfo(s);
                dr = dt.NewRow();
                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)
                {
                    MyFiles = new Dictionary<string, string>();
                    //files.Add(sysInfo.Name.ToString());
                    //files1.Add(info.Length.ToString());
                    //arr = string.Join("<br/>", files.ToArray());
                    //arr1 = string.Join("<br/>", files1.ToArray());
                    MyFiles.Add(sysInfo.Name.ToString(), info.Length.ToString());
                }

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

        if (arr != null)
        {
            ///Basic Email message
            MailMessage mailMessage = new MailMessage();
            // Email to send to
            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";
            //set body
            //mailMessage.Body = "THE FILES : <br/><br/>" + arr + arr1 + "<br/><br/> HAS REACH ITS SIZE LIMIT!!";
            mailMessage.Body = "THE FILES : <br/><br/>";
            foreach (string key in MyFiles.Keys)
            {
                mailMessage.Body += key + " = " + MyFiles[key] + "<br/>";
                mailMessage.Body += "<br/> HAS REACHED ITS SIZE LIMIT!";
            }
            mailMessage.IsBodyHtml = true;
            mailMessage.From = new MailAddress("************", "Shahrul Nizam");
            //Identify the credentials to login to the gmail account
            string sendEmailsFrom = "**********";
            string sendEmailsFromPassword = "**********";
            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.UseDefaultCredentials = true;
            mailClient.Credentials = cred;
            mailClient.Send(mailMessage);
            //MessageBox.Show("Email Notification Sent!");
            //MessageBox.Show(fileList.ToString() + "overlimit!!");
        }
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
            count++;
            if (count == 600)
            {
                count = 0;
                timer.Stop();
                Application.Restart();
            }
    }
  • 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-02T10:46:29+00:00Added an answer on June 2, 2026 at 10:46 am

    Change this:

    /*step 1*/if ((info.Length / 1024) > 1500000)
                    {//my size checking and storing it in an array
                        files.Add(sysInfo.Name.ToString());
                        files1.Add(info.Length.ToString());
                        arr = string.Join("<br/>", files.ToArray());
                        arr1 = string.Join("<br/>", files1.ToArray());
                    }
    /*step 2*/mailMessage.Body = "THE FILES : <br/><br/>" + arr + arr1 + "<br/><br/> HAS REACH ITS SIZE LIMIT!!";
    

    to

    /*step 1*/if ((info.Length / 1024) > 1500000)
                    {//my size checking and storing it in an array
                        files.Add(sysInfo.Name.ToString());
                        files1.Add(info.Length.ToString());
                    }
    /*step2*/mailMessage.Body = "THE FILES : <br/><br/>";
    for(int i=0; i<files.Count; i++)
      mailMessage.Body += files[i] + " = " + files1[i] + "<br/>;
    mailMessage.Body += "<br/> HAS REACHED ITS SIZE LIMIT!!";
    

    The extra <br/> at the last instance of the lists won’t matter because the last lines start with 2 breaks (I removed one).

    The suppositions I make:

    • The lists are of the same size
    • Each index in one, corresponds to the item in the other.

    This could be done better with a DICTIONARY (of type ) like so:

    /*step 1*/if ((info.Length / 1024) > 1500000)
                    {//my size checking and storing it in an array
                        /* I suppose there is a Dictionary<string, string> MyFiles;
                        MyFiles = new Dictionary<string,string>(); instantiated like so*/
                        MyFiles.add(sysInfo.Name.ToString(), info.Length.ToString());
                    }
                    //attaching the array to the email body
                        /*step 2*/mailMessage.Body = "THE FILES : <br/><br/>";
                        foreach(string key in MyFiles.Keys)
                          mailMessage.Body += key + " = " + MyFiles[key] + "<br/>";
                        mailMessage.Body += "<br/> HAVE REACHED THEIR SIZE LIMIT!!";
    

    Note that by better I do NOT mean more memory efficient. By better I mean less error-prone. Technically you have a key-value pairing. That is a dictionary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got yet another deployment problem. What I have: little Windows Forms application that
I have a little problem... I have made an Android application which extends the
I have a little problem with javascript form submit issue, here is the script
I need a little push in the right direction. Here's my problem: I have
I'm new around here and i have a little problems with a C# application.
I have this little problem, that I cannot figure out which arguments to pass
I have got a problem. I have windows forms application with dynamic generated layout,
I've got a little problem on a goDaddy server. I have a php script
I have got a little problem with repositioning a div that should serve as
I've got a little stuck with a small problem here: I use serialport communications

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.