Wednesday, September 2, 2009


For a few months now, I've been reading a little bit about android and playing around with the sdk (downloadable from with Eclipse. Too bad I dont have a G1 phone to test it out, but soon.

So android as some of you might know is the next generation platform for mobile devices. Not all mobile devices in the market support android. HTC, Samsung and Sony have a few G1 phones with T Mobile and Verizon has offcially announced that they are coming up with an android phone soon. It will probably be Motorola's Calgary phone.

A lot of cool applications can be developed using Android and, when I say cool, I mean it. You can control any hardware component of your android phone, including camera, your touch screen, keys, buttons and whatever hardware your phone contains. For instance, lets say you are a vivid reader and you are at a book store and have picked a book you like but would like to check prices for the same book online right there. You can take a picture of the book's barcode using your android phone and an android application can obtain the book's information by searching online stores (you can REALLY write an application that would grab the ISBN code and search popular websites for the book just by controlling your camera). The concept however is called Pattern Recognition I think, if you are geeky and want a name for it.

Alternatively, if you are just a fan of visuals, and if you have a Blackberry, you can create themes which makes your blackberry OS look like android. You would need the theme desginer from Blackberry's website. It is called Plazmic CDK 4.7. You also will need a device emulator for your phone.

Monday, August 24, 2009

Resolve your

There are times when you want to do something with the URL, or portions of the URL by parsing it. However, if you are on your local box, you are only going to see the good old AKA "localhost" in your URL. Lets say you want to parse http://msdn/testapplication so as to get only the 'msdn' part of the URL. You wont be able to do it on your local box because IIS would resolve your hostname to localhost.

Here's what you can do to mask a real-time url over your localhost.
From your file explorer, locate the etc folder under:


Here, you can see a file named hosts, of type file. Open it with a word editor program (notepad), and you will see the mappings of IP addresses to host names. You will by default, see an entry for resolved/mapped to localhost. All you need to do is change the name from localhost to whatever name (msdn, in our example). Now, when you type http://msdn/testapplication, you will actually be firing up your local web application. Now, you can do whatever you wish to do with the url since it is not "localhost" anymore, linguistically speaking.

I hope that was a cool trick that comes in handy! Until next time...

Wednesday, August 19, 2009

Export to Excel

I like inventing something on an as-needed basis, yes. How often does that happen though?! Then I thought how cool it would be if I just innovate or derive from existing technology?

To cut it short, here's the problem:
Lets say you have a scenario where you want to export something right from the database (and from the data layer) to excel and the excel workbook should be downloadable through any of your web interface components. I am not talking about just having a tabular data being exported to Excel but, a workbook with multiple worksheets (which has data from different tables in a dataset), styles, headers, formulas, expressions, content formatting, and much more. Its just a major pain to do all this. Its definitely possible but sometimes its just not worth the time. A simple example would be creating an invoice or orders (where the order information comes from the DL). Plus working with COM objects is not fun as they are not thread safe.

Here's a solution that cost you a bit of cash:
There are applications that would do the export to excel but they cost a few huyndred bucks. Plus they serve only one type. For instance there is a software that lets you create only invoices. You dont get control over "ALL" what you wanted to do here.

Here's mine:
What I tried and had worked pretty good for me was TEMLPATES. I had a template folder attached to my web app and had pre-formatted excel files there. That is, all they need is the data from the database. They will have the formulas, formatting, styles and so on already. So if you lets say drop in 2 rows of numbers from the database to one of these files and want the total in a different cell, the precalculated formula for that cell will automatically drop the total for you. So, you open the appropriate file from the templates folder using FileStream and Workbook Objects. The workbook object is a part of the Microsoft.Interop.Excel namespace. MSDN has a few good resources on how to open an Excel file. So, once you have your template, you can just drop the values from a dataset or datareader to the appropriate cells and then save the file in a different location with a different name for the user to download from. I usually attach a GUID to the filename or an id from the database that uniquely identifies the file. Now, you have a neat excel sheet with values from DB and formatting from a template.Of course, the user doesn't know this and doesn't care. All he needs to know is that he gets a kickass downloadable XLS file from a web page.

Last but not least, you should close the Excel applocation object (as it is thread unsafe) and dispose of any COM resources that you used.

Easy as it sounds, it is easily few hours of work if you are familiar with COM objects and FileStreams. If your computer crashes in the process, do not email me. If it doesn't and you have problems, I'd be glad to help.