Click here to Skip to main content
Click here to Skip to main content

ZipTrack

By , 2 Dec 2009
Rate this:
Please Sign up or sign in to vote.
Prize winner in Competition "Best VB.NET article of December 2009"

ZipTrack - Main Screen

Introduction

Over the years, I've collected quite a few code and program examples. The problem is that sometimes I may remember I have an example of how to do something, but I can not find it. This program is designed to scan my downloaded zip files and parse the documents inside, then insert the content information into a database that can further be used to provide RegEx search on.

To that end, it provides me with a sort of Zip library. As such, I can add bookmarks concerning each zip file that take me back to the original article for the zip archive.

Version 1.0

Technologies and design approaches demonstrated

  • SQL Express 2008 Datasource
  • Custom framework Datalayer
  • Strongly typed Dataset
  • ICSharpCode.SharpZipLib
  • ICSharpCode.TextEditor
  • Creational / Factory / Proxy / Singleton - Design Patterns
  • Customized User Controls
  • Custom GUI designers
  • Owner drawn controls

Requirements

Here is a step-by-step process for what you're going to need to do:

  1. Make sure you have SQL Server 2008 [^] installed on your machine.
  2. Ensure that you have the following DLL: ICSharpCode.SharpZipLib and ICSharpCode.TextEditor, from SharpDevelop [^] (included with the article download).
  3. Create the database on your own instance of SQL Server. The script can be found in the "...\Data\Create.dbArchive.sql" directory included with the solution.
  4. Change the ConnectionString property in the InitializeClass method of the Host class.
  5. Run the program. The sample website is included in the new database you created in the previous step.
  6. If you want to add one zip file at a time, click the "New archive" button.
  7. If you want to add several zip archives all at once, then click on the "Open" button located in the toolbar.
  8. Choose the website you want to associate with the file(s) that will be imported, and click the "Accept" button.
  9. Once this action is complete, click "Cancel" to close the form.
  10. By choosing the appropriate website from the [Website View], you should see the zip files that were found.
  11. You may choose to add one or more bookmarks after you have at least one zip file in [Zip File View].
  12. Once you select a Zip file on the left, its contents will be displayed in [Zip File Contents View] on the right.
  13. Select an ASCII text based file in [Zip File Contents View] and the file's contents will display in [File Content View].

ZipTrack - Main Screen

Definitions

Let's begin by defining the domain specific language used by this utility program:

  1. Archive - An Archive represents a Zip file (e.g., HelloWorld.zip).
  2. Bookmark - A Bookmark is an Internet shortcut stored in the database that links back to the original, or supporting web page article(s), and can be retrieved.
  3. Document - A Document is *any* content that is found inside a zip archive file (i.e., *.cs, *.txt, *.doc, *.dll, *.exe, *.vb, etc...).
  4. Website - Websites are used extensively by this program to associate each downloaded archive to an origination source.

Usage

uml

Typically, the scenario is that most users will already have multiple files that have been previously downloaded on to the desktop PC. What we want to do is create a library of those files for easy lookup at a future date. Thus, the need for ZipTrack to organize and manage those files.

Categories

Often times, I am led to several places across the internet that offer various tips / tricks / solutions. I needed a way to categorize what I found and where. The best way that I have found to accomplish this was to put all files into separate directories named for the website I download from (e.g., CodeProject, etc...).

Website Categories

Grouping

If you are like me, you have files that date back for more than just a couple of days, maybe even years. Using code found on the internet for listbox grouping, we can group our archives by date, much similar to the way that Microsoft Outlook groups email.

Archive Grouping

Searching

Probably the most beneficial part of this program is the ability to search within the zip archive(s) without having to unzip each file to examine its contents.

Archive Grouping

Datalayer architecture

The script file is included for you to re-create the database for your own SQL Server instance. The data layer consists of common inheritable objects that facilitate data retrieval and storage. The data layer consists of the following objects in no particular order:

  • Models - These objects provide a base class for any derived business class. The Business Object class inherits from the base class to share common functionality and properties.
  • Business Object - A business object that encapsulates all of the data and business behavior associated with the data table that it represents.
  • Manager Class - This Manager class is useful for easy access to the data store. All data is captured and supplied in this centralized repository. It serves as a creational design pattern to create and retrieve concrete business objects.
  • DataHandler - The DataHandler class provides a consistent interface to data available in many different sources and formats. It manages simple data requests, conversions, and related operations using DataRequestEventHandlers. It provides access to commands that can operate on the data.

Base model example

Namespace Common
    Public MustInherit Class Model

        Public MustOverride Property Name() As String

        Public MustOverride ReadOnly Property PrimaryID() As Integer

    End Class
End Namespace

Points of interest

One of the things that I found quite interesting during this project was when I needed a way to drag-n-drop shortcuts onto my form to help produce bookmarks. However, I needed a way to implement the GetData function for an Internet shortcut:

Drag-n-drop

Private Sub BookmarksGrid1_DragDrop(ByVal sender As Object, _
            ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
    If e.Data.GetDataPresent("UniformResourceLocator", False) Then

        Dim data As Object = e.Data.GetData("UniformResourceLocator")

        Dim ms As MemoryStream = TryCast(data, MemoryStream)
        Dim bytes() As Byte = ms.ToArray()
        Dim encod As Encoding = Encoding.ASCII
        Dim LnkText As String = encod.GetString(bytes)

        Me.CreateNew(LnkText)

    ElseIf e.Data.GetDataPresent("FileNameW", False) Then

        '------------------------------------------------
        'You can drag and drop items from the desktop or Explorer onto the DataGridView
        '------------------------------------------------

        'Dim names As System.Array = _
        '     CType(e.Data.GetData("FileNameW", False), System.Array)
        'Dim LnkText As String = ResolveShellLink(CStr(names.GetValue(0)))

        'Me.CreateNew(LnkText)

    End If
End Sub

ResolveShellLink

During my search, I also ran across a way to retrieve link information for desktop shortcuts to files. You can now drag and drop items from the desktop or Explorer onto the DataGridView. Note that you'll get an array of file names since you can select multiple files and drop them; I just utilize the first item. To use this functionality, 'Add Reference' to c:\windows\system32\shell32.dll.

Private Function ResolveShellLink(ByVal name As String) As String
    ' --- Find the target for a short-cut
    If String.Compare(Path.GetExtension(name), ".lnk", True) <> 0 Then Return name
    Dim shl As New Shell32.Shell
    Dim dir As Shell32.Folder = shl.NameSpace(Path.GetDirectoryName(name))
    Dim itm As Shell32.FolderItem = dir.Items().Item(Path.GetFileName(name))
    Dim lnk As Shell32.ShellLinkObject = CType(itm.GetLink, Shell32.ShellLinkObject)
    Return lnk.Path
End Function

Todo

Although not implemented here, I think that I might implement the file shortcut method in the future. Also perhaps implement a way to add new websites to the database. Happy coding!!!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

TL Wallace
Founder Arkitech EBC Corporation
United States United States
Developer, consultant, and trainer that specializes in building data-centric applications designed for small businesses, universities, community & faith based organizations. Started by developing Excel VBA macros in 1989 for businesses and never looked back. Since then I have gone on to author several programs using VB.NET, SQL Server, Microsoft Access, and ASP.net.

Comments and Discussions

 
GeneralMy vote of 5 PinmemberGuirec Le Bars18-Oct-12 23:37 
GeneralMy vote of 5 PinmemberRanjan.D28-Sep-12 5:05 
GeneralMy vote of 5 PinmemberPolinia13-Jul-12 3:08 
GeneralLooks really good - but a bit of a problem with date formats Pinmemberpt140115-May-10 8:37 
GeneralRe: Looks really good - but a bit of a problem with date formats Pinmemberpt140115-May-10 9:01 
GeneralUseful Application and Nice User Interface PinmemberIrwan Hassan27-Jan-10 14:31 
GeneralRe: Useful Application and Nice User Interface PinmemberTL Wallace27-Jan-10 17:33 
GeneralThis looks like it ROCKS! PinmemberRay Cassick21-Dec-09 5:08 
GeneralRe: This looks like it ROCKS! PinmemberTL Wallace21-Dec-09 9:44 
Thank you. If run into any 'features' Smile | :) just let me know.
 
"If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." - Red Adair

Generalhe :) Pinmemberkonikula20-Dec-09 12:36 
GeneralA Good work Pinmemberinfinitess7-Dec-09 16:05 
GeneralRe: A Good work PinmemberTL Wallace9-Dec-09 6:21 
GeneralVery interesting, got 5 from me PinmemberMarcelo Ricardo de Oliveira7-Dec-09 11:03 
GeneralRe: Very interesting, got 5 from me PinmemberTL Wallace7-Dec-09 11:08 
GeneralVery Good App [modified] Pinmemberrspercy605-Dec-09 4:58 
GeneralRe: Very Good App PinmemberTL Wallace6-Dec-09 13:20 
GeneralRe: Very Good App Pinmemberrspercy606-Dec-09 13:31 
GeneralRe: Very Good App PinmemberTL Wallace6-Dec-09 13:44 
GeneralRe: Very Good App PinmemberTL Wallace6-Dec-09 14:08 
GeneralRe: Very Good App Pinmemberrspercy606-Dec-09 15:09 
GeneralRe: Very Good App PinmemberTL Wallace6-Dec-09 15:15 
GeneralRe: Very Good App Pinmemberrspercy6012-Dec-09 4:39 
GeneralNice - Thanks PinmemberChrisHar4-Dec-09 3:43 
GeneralRe: Nice - Thanks PinmemberTL Wallace6-Dec-09 13:14 
GeneralVery handy PingroupDev_25803-Dec-09 20:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web02 | 2.8.140415.2 | Last Updated 3 Dec 2009
Article Copyright 2009 by TL Wallace
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid