Archive for Maggio 27th, 2008

Using ZIPLIB

CodeKeep C# Feed Maggio 27th, 2008

Description: How to use the ziplib on the fly

Link: http://www.codekeep.net/snippets/dc6c17a3-4d8d-4fb9-9e08-7592b2a8c377.aspx

using System;
using System.IO;

using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;

class MainClass
{
    public static void Main(string[] args)
    {
        string[] filenames = Directory.GetFiles(args[0]);
        byte[] buffer = new byte[4096];

        using ( ZipOutputStream s = new ZipOutputStream(File.Create(args[1])) ) {

            s.SetLevel(9); // 0 - store only to 9 - means best compression

            foreach (string file in filenames) {
                ZipEntry entry = new ZipEntry(file);
                s.PutNextEntry(entry);

                using (FileStream fs = File.OpenRead(file)) {
                    StreamUtils.Copy(fs, s, buffer);
                }
            }
        }
    }
}

Button Event handler

CodeKeep C# Feed Maggio 27th, 2008

Description: change the name

Link: http://www.codekeep.net/snippets/22f612e6-79b2-449b-8987-2df154c1e48c.aspx

#region event handlers
        protected void ButtonEventHandler(object sender, EventArgs e)
        {
        }
        #endregion event handlers

Exception handling inititlization

CodeKeep C# Feed Maggio 27th, 2008

Description: Exception handling inititlization

Link: http://www.codekeep.net/snippets/ba986589-dd21-4056-80ff-273d418331f7.aspx

            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(ExceptionHandler);
            Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);