Tuesday, July 17, 2007
It's been a while since I needed to work with zip files, so when I found myself writing a small routine that periodically downloads and processes a Zip file, I need a quick and cheap (note: by cheap I mean free) method to decompress said file. Of course there are countless number of commercial components available, but most come with a hefty price tag. All I need is to extract a file. Wait, doesn't Windows include the ability to work with compressed folders?

Sure enough, Shell32 (Found in C:\Windows\System32\Shell32.dll) offers methods to extract and create Zips! So with a reference to Microsoft Shell and Automation Controls (Which will create an Interop assembly, Interop.Shell32.Dll), and some handy Googling, I was able to create a small class with 2 methods:
  • UnzipFileTo(zipPath, pathtoExtract): Extracts files in zipPath to pathtoExtract
  • ZipFolder(srcfolderString, dstfolderString): Compresses all files in srcFolderString to dstfolderString

Note: This method does display a Progress Dialog (Even though the proper options have been passed to the CopyHere method), so make sure to handle existing files and paths prior to using.

Below you will find this class in both Visual Basic and C Sharp compatible with Framework 2.0 and above.

Comments and suggestions always welcome!

Visual Basic:

Imports System.IO
Imports Shell32
Public Class ZipControl
    Public ErrorMsg As String = ""
    Public Function UnzipFileTo(ByVal zipPath As String, ByVal pathtoExtract As String) As Boolean
        Try
            Dim sc As New Shell32.ShellClass()
            Dim SrcFlder As Shell32.Folder = sc.NameSpace(zipPath)
            Dim DestFlder As Shell32.Folder = sc.NameSpace(pathtoExtract)
            Dim items As Shell32.FolderItems = SrcFlder.Items()
            DestFlder.CopyHere(items, 4 + 20 + 10 + 200)
        Catch ex As Exception
            Me.ErrorMsg = ex.Message
            Return False
        End Try
        Return True
    End Function
    Public Function ZipFolder(ByVal srcfolderString As String, ByVal dstfolderString As String) As Boolean
        Try
            Dim fileContents() As Byte = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
            File.WriteAllBytes(dstfolderString, fileContents)
            Dim oShell As New Shell32.ShellClass
            Dim oFolderSrc As Shell32.Folder
            Dim oFolderDst As Shell32.Folder
            Dim oFolderItems As Shell32.FolderItems
            oFolderSrc = oShell.NameSpace(srcfolderString)
            oFolderDst = oShell.NameSpace(dstfolderString)
            oFolderItems = oFolderSrc.Items()
            oFolderDst.CopyHere(oFolderItems, 4 + 20 + 10 + 200)
        Catch ex As Exception
            Me.ErrorMsg = ex.Message
            Return False
        End Try
        Return True
    End Function
End Class

C#:

using System;
using Shell32;
using System.IO;
public class ZipControl
{
    public string ErrorMsg = "";
    public bool UnzipFileTo(string zipPath, string pathtoExtract)
    {
        try
        {
            Shell32.ShellClass sc = new Shell32.ShellClass();
            Shell32.Folder SrcFlder = sc.NameSpace(zipPath);
            Shell32.Folder DestFlder = sc.NameSpace(pathtoExtract);
            Shell32.FolderItems items = SrcFlder.Items();
            DestFlder.CopyHere(items, 4 + 20 + 10 + 200);
        }
        catch (Exception ex)
        {
            this.ErrorMsg = ex.Message;
            return false;
        }
        return true;
    }
    public bool ZipFolder(string srcfolderString, string dstfolderString)
    {
        try
        {
            byte[] fileContents = {80, 75, 5, 6, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0};
            File.WriteAllBytes(dstfolderString, fileContents);
            Shell32.ShellClass oShell = new Shell32.ShellClass();
            Shell32.Folder oFolderSrc;
            Shell32.Folder oFolderDst;
            Shell32.FolderItems oFolderItems;
            oFolderSrc = oShell.NameSpace(srcfolderString);
            oFolderDst = oShell.NameSpace(dstfolderString);
            oFolderItems = oFolderSrc.Items();
            oFolderDst.CopyHere(oFolderItems, 4 + 20 + 10 + 200);
        }
        catch (Exception ex)
        {
            this.ErrorMsg = ex.Message;
            return false;
        }
        return true;
    }
}

posted on Tuesday, July 17, 2007 12:30:42 AM (Eastern Standard Time, UTC-05:00)  #    Comments [1]
 
 Wednesday, January 31, 2007

Last year I decided to upgrade my laptop (An Averatec with a 15" screen), for something more lightweight. I had seen several ultra portables which made me drool! After some research and bargain shopping, I came across a nice unit, the HP Compaq NC4010 (CNET's Review). One of the selling points of the unit, was that it came "Windows Vista Ready". I was certain I would be making the move to the new operating system as soon as it launched, so I figured I may as well purchase a notebook which will be ready for the future. This option actually overweighed the short battery life (I purchased an extra battery, which doesn't affect its portability much).

Well, after much waiting, Vista finally arrived. I eargely loaded the OS unto my trusty nc4010, only to find that the video drivers were not found, all that was listed in Device Manager was a Standard VGA Adapter! What the truck? After scouring HP's Support web site I was unable to find Vista drivers. After several calls to HP's support center and hours wasted on hold, I've been told that HP does not support Windows Vista on the NC4010!!!

Excuse me? So this "Windows Vista Ready" sticker on the machine and the packaging means absolutely what? It was my impression that false advertising was considered a crime in the United States? Well, I guess from HP's executive actions, crime is not a concern. Well, I guess it's back to XP for now, 800 X 600 at 8 Bit just doesn't do Vista justice.

 

posted on Wednesday, January 31, 2007 11:25:14 PM (Eastern Standard Time, UTC-05:00)  #    Comments [3]
 
 Wednesday, October 25, 2006
Using your Motorola Q or other Windows Mobile 5.0 device isn't so straight forward if you'd like to use SSL and are not using one of the 5 Trusted Certification Authorities, this will show you how to add your certificate to your device.
posted on Wednesday, October 25, 2006 12:10:10 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]
 
 Tuesday, October 03, 2006
Ever need to connect to that PC you just added to the network? Did you forget to enable Remote Desktop? No Worries! No need to get up, as long as you have access to the PC via Network you can enable Terminal Services remotely!
posted on Tuesday, October 03, 2006 1:19:39 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]
 
 Friday, September 29, 2006
If you are using version 4 of DotNetNuke's Events module and wonder why the price it wants to send to Pay Pal is always $0.00, then here is a quick fix.
posted on Friday, September 29, 2006 2:39:11 PM (Eastern Standard Time, UTC-05:00)  #    Comments [2]
 
 Wednesday, September 27, 2006
How to use TSDISCON command utility tool to disconnect remote desktop sessions on another server from the command line.
posted on Wednesday, September 27, 2006 1:34:11 PM (Eastern Standard Time, UTC-05:00)  #    Comments [1]
 
 Tuesday, September 26, 2006
Yay, I could finally copy files between computers using remote desktop! You too can copy file while connected to a computer using remote desktop connection.
posted on Tuesday, September 26, 2006 10:18:38 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0]
 
 Thursday, September 21, 2006

Apparantely someone at WalMart got a little ansy about adding the Microsoft Zune to their online database. Based on some reports, for a short time yesterday, Walmart had the Zune listed at a retail value of $284.00. Question is, was this price set prior to Apple dropping the price on their 30GB iPod down to $249.00 from $299.00? Will Microsoft come in even lower for this wonderful Zune we all keep hearing about?

Walmart has a whole section dedicated to the Zune.

Only time will tell....

 

UPDATE

It's seems someone at Microsoft leaked the final price of the Zune - Drumroll please - $229.00. Apparantely they've decided to drop some pre-loaded content to make the price below that of Apple's iPod.

posted on Thursday, September 21, 2006 10:39:48 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0]