通过电子邮件并排发送两个列表? [英] Send two list side by side through email?

查看:91
本文介绍了通过电子邮件并排发送两个列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.我这里有一个小问题.我得到了一个应用程序,该应用程序通过电子邮件发送文件名列表,通知用户这些文件已超过特定大小限制.但是现在我希望它不仅发送文件名,而且发送文件大小.我设法将文件大小附加到电子邮件中.但是我的问题是它的显示方式.我希望它显示为:

文件:

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

已达到其极限!

但是我当前在电子邮件中的显示格式如下:

文件:

filename1
filename2
filename3
filesize1
filesize2
filesize3

已达到其极限!

现在,我不知道如何像第一个一样更改显示格式.任何帮助将不胜感激.这是我的资料来源:

Hi there guys. 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 source :

//My size checking and store it into a list.
 if ((info.Length / 1024) > 1500000)
{
     files.Add(sysInfo.Name.ToString());
     files1.Add(info.Length.ToString());
     arr = string.Join("<br/>", files.ToArray());
     arr1 = string.Join("<br/>", files1.ToArray());
}





//attaching the list to an email body
mailMessage.Body = "THE FILES : <br/><br/>" + arr + arr1 + "<br/><br/> HAS REACH ITS SIZE LIMIT!!";

推荐答案

请在下面看看,

Please have a look below,

using System;
using System.IO;
using System.Linq;
using System.Text;

namespace Chapter_5
{
    class Program
    {
        static void Main()
        {
            string directoryName = @"C:\\textfiles";
            Console.WriteLine(FindFileswhichReachedLimit(directoryName));
        }

        static string FindFileswhichReachedLimit(string directoryName)
        {
            StringBuilder builder = new StringBuilder();
            Directory.GetFiles(directoryName)
                .Where(file =>
                {
                    return IsReachedMax(Path.Combine(directoryName, file));
                })
                .Select(file =>
                {
                    return string.Format("{0,40}\t{1}{2}",
                        Path.GetFileName(file),
                        GetFileSize(Path.Combine(directoryName, file)),
                        Environment.NewLine);
                }).ToList().ForEach(fileInfo => builder.Append(fileInfo));
            return builder.ToString();

        }

        static bool IsReachedMax(string fileName)
        {
            // I modified the condition to test So please updated as yours
            return GetFileSize(fileName) / 1024 < 1500000;
        }

        static long GetFileSize(string fileName)
        {
            return (new FileInfo(fileName)).Length;
        }
    }
}



希望对您有所帮助:)

第二版:



Hope it helps :)

2nd Version:

class Program
{
    static void Main()
    {
        string directoryName = @"C:\\textfiles";
        Console.WriteLine(FindFileswhichReachedLimit(directoryName));
    }

    static string FindFileswhichReachedLimit(string directoryName)
    {
        StringBuilder builder = new StringBuilder();
        IList<string> files = Directory.GetFiles(directoryName);
        foreach (string file in files)
        {
            if (IsReachedMax(Path.Combine(directoryName, file)))
            {
                string fileInfo = string.Format("{0,40}\t{1}{2}", 
                    Path.GetFileName(file), 
                    GetFileSize(Path.Combine(directoryName, file)), 
                    Environment.NewLine);
                builder.Append(fileInfo);
            }

        }
        return builder.ToString();
    }

    static bool IsReachedMax(string fileName)
    {
        // I modified the condition to test So please updated as yours
        return GetFileSize(fileName) / 1024 < 1500000;
    }

    static long GetFileSize(string fileName)
    {
        return (new FileInfo(fileName)).Length;
    }
}


由于我们不知道sysInfo派生的类,因此没有人能够真正为您解决此问题.通常,文件信息由FileInfo类提供. FileInfo具有长度,文件名等属性.

如果您有某种方法可以获取要输出的文件的大小,则可以执行以下操作:

Nobody is going to be able to really help you with this problem since we do not know what class sysInfo derives from. Normally file info is provided by the FileInfo class. The FileInfo has properties for length, file name, etc.

If you have some way to get the size of the file you are outputting then the following will work:

if ((info.Length / 1024) > 1500000)
{
     files.Add("{0,40}\t{1}", sysInfo.Name, info.Length);
}
arr = string.Join("<br/>", files.ToArray());
arr1 = string.Join("<br/>", files1.ToArray());


这篇关于通过电子邮件并排发送两个列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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