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.
Technologies and design approaches demonstrated
- SQL Express 2008 Datasource
- Custom framework Datalayer
- Strongly typed Dataset
- Creational / Factory / Proxy / Singleton - Design Patterns
- Customized User Controls
- Custom GUI designers
- Owner drawn controls
Here is a step-by-step process for what you're going to need to do:
- Make sure you have SQL Server 2008 [^] installed on your machine.
- Ensure that you have the following DLL: ICSharpCode.SharpZipLib and ICSharpCode.TextEditor, from SharpDevelop [^] (included with the article download).
- 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.
- Change the
ConnectionString property in the
InitializeClass method of the
- Run the program. The sample website is included in the new database you created in the previous step.
- If you want to add one zip file at a time, click the "New archive" button.
- If you want to add several zip archives all at once, then click on the "Open" button located in the toolbar.
- Choose the website you want to associate with the file(s) that will be imported, and click the "Accept" button.
- Once this action is complete, click "Cancel" to close the form.
- By choosing the appropriate website from the [Website View], you should see the zip files that were found.
- You may choose to add one or more bookmarks after you have at least one zip file in [Zip File View].
- Once you select a Zip file on the left, its contents will be displayed in [Zip File Contents View] on the right.
- Select an ASCII text based file in [Zip File Contents View] and the file's contents will display in [File Content View].
Let's begin by defining the domain specific language used by this utility program:
- Archive - An Archive represents a Zip file (e.g., HelloWorld.zip).
- 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.
- Document - A Document is *any* content that is found inside a zip archive file (i.e., *.cs, *.txt, *.doc, *.dll, *.exe, *.vb, etc...).
- Website - Websites are used extensively by this program to associate each downloaded archive to an origination source.
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.
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...).
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.
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.
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
Public MustInherit Class Model
Public MustOverride Property Name() As String
Public MustOverride ReadOnly Property PrimaryID() As Integer
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:
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)
ElseIf e.Data.GetDataPresent("FileNameW", False) Then
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
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)
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!!!