Create your personalized web signature

Some website, eg, provides customized signature that shows the ip address, the ISP, the OS and browser. You also can DIY your own with your style.

This article is for anyone who has basic network knowledge and is interested in DIY and it will guide you from start to finish so you get the full picture.

  1. Apply a free web hosting with PHP supported
  2. Download GeoIP.dat, and to your local drive
  3. Create and save ip.php as shown below
  4. Upload ip.php, GeoIP.dat, and to your new web space
  5. Open your browser and type “http://somespace.somespace/ip.php


Decorate your .Net WinForm application in a peculiar way

This article actually was written in last Christmas, now I just re-post in my new home.

Every programmer wants his application GUI to stand out, and so do I. A new idea came into my mind. I would like to add a Christmas hat on the top left corner of my WinForm application. This is not only simple but also not adding too much work load.

.Net application skin could be the first solution for most programmer. But it seems not worth it, because a huge skin library has to be installed just for this simple function. Furthermore, commercial skin library is not free at all.

I have to go back google again. Someone mention that it can override WndProc and in WM_NCPAINT, you have to draw your own title bar, and write function for each button. It seems a lot of work to do.Finally, I invent this peculiar way.

1. Create a transparent Form,
2. Put only a hat inside
3. Let it stay on the top left corner

private void Form1_LocationChanged(object sender, System.EventArgs e)
    hat.Location = new Point(this.Location.X-30,this.Location.Y-10);

private void Form1_Activated(object sender, System.EventArgs e)
        hat.TopMost = true;

private void Form1_Deactivate(object sender, System.EventArgs e)
        hat.TopMost = false;
} dynamically generate MS Word document (3)

If you are following the previous two articles, you will see a “Word” document in your frond. However, you may find some glitches in this document and there is a hidden box on top of the document. This is because ASP.Net generates “__VIEWSTATE” hidden view to track each page status.

We don’t want this field to be displayed as this should be a final “Word” document without any attached strings. To get rid of this, we have to override Render method.

protected override void Render(HtmlTextWriter writer)
  StringBuilder sb = new StringBuilder();
  HtmlTextWriter htw = new HtmlTextWriter(new StringWriter(sb));
  sb = sb.Replace(""

You should have a complete “Word” document right now. dynamically generate MS Word document (2)

MS Word treat this generated “Word” document differently

When clicking download generated document, IE will pop up “File Download” dialog as expected. However when opening the downloaded document, MS Word will be in “Web Layout View” instead of “Print Layout View”.

Let MS Word “thinks” this is true word document and open in “Print Layout View” with zoom “90%

Replace original Visual Studio automatically generated .aspx header with the following code

OK! Now when MS Word opens this html style Word document, it more likely opens a real Word document.

Another issue comes up that MS Word is so smart, and it automatically breaks the page.

If you want to break the page on a certain position, you can insert the following code into your html style Word document.

Previous page

Next page dynamically generate MS Word document (1)

Currently I am using and working on a web project, which requires dynamically generate Microsoft Word submission document. The generated document must be specific format, and include page number, last print date, company logo, etc.

At first, I was thinking of using COM (Component Object Model). Because MS Word can comfortably work with .Net framework, .Net provide easy runtime callable wrapper. But it requires MS Word to be installed at server side, and it may slow down web server running. I have to give up.

And then I was looking for 3rd party .Net library generate MS Word. It’s not a cheap solution either.

After google, finally I found out that MS Word is compatible with HTML file format. As long as you rename .htm to .doc. MS Word can easily open. What I can do is to create a html template and then filled out the dynamic sections and response back to end user.

Here is the code snap shot:

protected void Page_Load(object sender, EventArgs e)
  if (this.Request["projectID"] != null)
    //fill dynamic section
    //add word document header to response
    Response.AddHeader("content-disposition", "attachment;filename=Submission.doc");
    Response.Charset = "utf-8";
    Response.ContentType = "application/ms-word";
    //flush out whole page to word document
    System.IO.StringWriter stringWrite = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

I will keep posting the problem that I met and the solution in the next few posts.

Android on my SuperPad

Recently, I bought a SuperPad from eBay for my kid learning, which is running Google Android 2.1.

It’s pretty cool because I can develop my own educational application for my kid.  As I haven’t been playing Java for a long time, I have to refresh my memory, and it will slow down the process a little bit.

Download Eclipse IDE, Android simulator, setup development environment… Finally I have my HelloWorld running!!!!!! It’s so excited to see these two words appearing in my new SuperPad screen.

After few days’ trial, I have two applications ready for my kid Kids Draw and Spot the Difference.