C# zipping files and emailing

Posted on 2005-04-15
Last Modified: 2012-05-05
I have a folder which has say 10 files, I want to zip these 10 files together into one single zip file and email to a given email address as an attachment. I am using C# for this application. Please give me some suggestions as to how it can be done using C#.
Question by:sunilramu
    LVL 3

    Accepted Solution

    For zipping, Component One, has a commercial Zip feature. Another one that I've used, which is GPL, is SharpZipLib. You can find it at
    LVL 8

    Assisted Solution

    >>Does .NET have any compressiong/zipping capabilities?
    The .NET framework doesn't contain any general purpose compression libraries, but there are plenty of third-party libraries available. The most commonly referenced is probably SharpZipLib, which is free and open source but may still be used in commercial applications.

    LVL 14

    Assisted Solution

    To zip the files you can use the given suggestions above. You can e-mail it the following way:

    using System.Web.Mail;
    MailMessage mail = new MailMessage();
    mail.To = "";
    mail.From = "";
    mail.Subject = "this is a test email.";
    mail.Body = "this is my test email body.";
    MailAttachment attachment = new MailAttachment( "test.txt" );
    mail.Attachments.Add( attachment );
    SmtpMail.SmtpServer = "localhost";
    SmtpMail.Send( mail );

    Note: System.Web.Mail is a part from ASP.NET, so you need that installed also.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now