Archive for February 2008
Create A Simple Dynamic Clock by Using UpdatePanel of ASP.NET AJAX
If you are developing web applications for different customer scenarios in which timestamping matters, there is a chance that you will be asked to put a real-time dynamic clock on the page depending on your real estate limitations on the UI. Any search result would give you several remedies to this purpose, but I wanted to have something short, neat and cross-browser compatible.
Here is the solution that I came up with by using an UpdatePanel and a few lines of JavaScript code.
First, create the UpdatePanel as in the following sample form:

OnLoad event of upDynamicClock will be handled in the server side:

Create a listener function (DisplayDynamicClock) by using the native setInterval function of JavaScript in order to update the content of lblDynamicClock and tell the page to run this function via window.onload:

Notice the usage of “__doPostBack” function as a bridge between JavaScript and ASP.NET for triggering a postback at upDynamicClock.
Conclusion
I have tested the outcome with the latest versions of IE and Firefox, and it worked fine with both of them:


Download
Sample code for this post can be found here.
Extract Zip File By Using SharpZipLib Library in ASP.NET
If you are developing an IO style application, it is a high possibility that one of the requirements would ask you a utility to extract an uploaded zip file. Well, here is a one way to accomplish this with VB.NET by using the SharpLibZip library.
After downloading the appropriate binary file and placing it to the Bin directory of your project, let’s have the webform similar to the following:

HTML presentation of this webform should look like:

Click event of Button1 is the one using the ExtractZip class:

Now, time to delve into the ExtractZip class! Code speaks pretty well for itself, therefore I will not be putting detailed description. Parameters are:

Before jumping into the extraction, it would be a good practice to perform some simple checks:

And, the Try Catch statement doing the main job is:

Delete the original zip file if the optional DeleteZip parameter was left as True:

Download
Working sample of this ExtractZip class can be downloaded via here.