如何压缩目录并将其发送到邮件(附加为zip文件) [英] How to zip a directory and send it to a mail (attach as zip file)

查看:117
本文介绍了如何压缩目录并将其发送到邮件(附加为zip文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想压缩目录/文件夹并将其发送到邮件地址。

谁能告诉我怎么做?



假设文件夹名称 -

C:/ Pavel



我想要压缩这个完整的文件夹/目录 -

C:/pavel.zip



在zip完整目录之后会发送到一个电子邮件地址。



谢谢

I wanna zip a directory/folder and send it to a mail address.
can anyone tell me how to do this?

Suppose folder name -
C:/Pavel

I wanna compress this full folder/directory to -
C:/pavel.zip

after zip full directory this will be send to a email address.

Thanks

推荐答案

使用.NET 4.5,添加对System.IO.Compression的引用。 FileSystem并执行以下操作:



Using .NET 4.5, add a reference to System.IO.Compression.FileSystem and do the following:

static void Main(string[] args)
{
    string startPath = @"c:\Pavel";
    string zipPath = @"C:\Pavel.zip";

    ZipFile.CreateFromDirectory(startPath, zipPath);
}





然后按照本文的说明将文件附加到电子邮件:

http://msdn.microsoft.com/en-us/library/ system.net.mail.mailmessage.attachments.aspx [ ^ ]


这篇关于如何压缩目录并将其发送到邮件(附加为zip文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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