Cool .NET Tips and Tricks #16
By Dr. Dexter Dotnetsky
Printer - Friendly Version
Dr. Dotnetsky

Well, Howdy! It's me again, they let me out (on "good behavior only" probation of course) for another of my rants! Well we sure got a strange political process here is these United States of A-Merica! It seems that if you are a Republican, good is not always so good, and if you are a Democrat, bad is always good!



Good is Bad?

President gives a State of the Union speech, says the truth: " Americans took those dollars and put them to work, driving this economy forward. The pace of economic growth in the third quarter of 2003 was the fastest in nearly 20 years. New home construction: the highest in almost 20 years. Home ownership rates: the highest ever. Manufacturing activity is increasing. Inflation is low. Interest rates are low. Exports are growing. Productivity is high. And jobs are on the rise."

if you remember, the Republican side of the chamber gave this part a standing ovation; the Democrats sat on their hands. Ted Kennedy sat there red-faced and looked as if somebody had just killed his mother. I suppose it's because they think low inflation, high economic growth, and such are bad or anti-American or something. Of course, now we see 500,000 new jobs since August 2003 with an expected 2 million new jobs by the end of 2004, and of course the first thing out of Kerry's mouth is, "We now hear the administration claiming economic success. But the definition of economic success should not be losing 2.6 million jobs in the private sector.''

DUH! Presidents are rarely "responsible" for recessions, unless their policies are so absolutely bad that they actually cause one. In point of fact, Mr. Bush's administration inherited the recession which began before he ever took office - during the Clinton years.

Dean appealed to the Democrat base because he appealed to their anger, to their resentment, to their hatred of the success of President Bush's administration. When Kerry, the most ultra-liberal Dem of all, moved up and usurped Dean, it was because the base realized that he could also appeal to their anger, resentment, and hatred of Dubya. Its pretty obvious there is no such thing as a "Moderate" Democrat any longer - R.I.P. Joe Lieberman for proof! And how about Nader - that guy is now deal-making with both major parties! I wonder what's up his Greensleeve?

Now there is some "real" bad news on the horizon. The CRB index and gold prices are moving up steadily, and that is clearly a solid hint of inflation to come soon. (Oh, and did I forget to mention gas prices -- if you don't think $2.00 a gallon gas is inflationary, I got this here deal on a bridge in Brooklyn...). With that will come higher interest rates and economic contraction - but not for at least another year (don't forget the last recession actually got started in 2000 -- so a new one is just around the corner).

Windows XP Service Pack 2

Well, Dr. Dotnetsky checked in at MSDN Subscriber Downloads and lo - there was XP Service Pack 2 Release Candidate 1!   So I downloaded the sucker and burned the ISO onto a spare blank. Well, this thing is something else! I'm starting to wonder if it may end up only being suitable for a Martini coaster -it must have taken an hour to install. Then when it comes up, I'm in 640X480 mode (it completely ignored my ATI Radeon 7000 driver - probably one of the most common there is) and showed me this stupid "Security Screen" that now I can't navigate because it's too big for the 640X480 VGA default "No driver" mode.

So poor old Doc has to navigate around blind, pretty much guessing where the dang buttons may be and which one will get pressed if he hits the ENTER key. I did manage to turn of the Firewall thingy, I'm behind a wireless router firewall anyway and nothing gets in unless I want it to come in.

The next thing it does is tell me I have no Virus Protection. DOH! I'm running Norton Corporate 8.1 Client, and I see the familiar shield still sitting there right on the task bar! C'mon guys, this is a RELEASE CANDIDATE, and it can't even detect Norton!? You know, isn't the RC that one that you give to all the reviewers so they can write articles about it? The one that (historically) has been virtually feature-identical to the final public version? Well, the last insult is that the thing now has this "shield" like McAffee's taskbar shield that it keeps running in the taskbar, using up resources and ostensibly it's there to protect me, "springing into life" whenever it detects that I've been bad or usen a stolen password, or whatever the hell it's supposed to do. But not to worry, I'll figure out how to disable that too, and right fast!

I understand that there are a lot of good security - oriented fixes in the Service Pack, but let's remember - the presentation is 95% of the picture for the end user.

What's New Dept.

Well those dudes at eggheadcafe.com have been a busy bunch in the last week or two. Bromberg has a generic CAPTCHA image implementation he wrote about, both Morris and Bromberg have done articles on using the CryptoAPI on the Compact Framework. Hart has a nice article on the CF with webservice and another about customizing an ASP.NET textbox control. And Swanepoel has an interesting new article about parsing HTML with MSHTML.DLL. Yours Truly, The Doctor, back from a rehab trip hopping trains from Phoenix with notebook in hand, has been in rare form on their forums. So, check it out, DUDEN! Feed yer brain, don't complain, and RTFM till yer eyes turn blue!

Out on the Net

Daniel Cazzulino, of Deverest, NMatrix and ASP.NET Server Controls (Wrox) fame, has a very interesting post on his blog about the MVP Xml project (started by XML MVP's) and his XPath Cache.

Out at Sourceforge.net, Manuel Lucas Viñas Livschitz has created a very interesting fast and very small C# implementation of a multi-threaded, blackout-safe database engine, HyperNetDatabase, complete with a pretty interesting implementation of SQL in it to boot. Dr. Dotnetsky sez, "Check this one out" - and you know Dr. Dotnetsky would not play you wrong! Somebody should port this baby to the Compact Framework!

Streaming Excel to the User's Machine With the Correct File Extension Department:

1) Create a class that implements System.Web.IHttpHandler
2) Code the ProcessRequest method with your stuff to populate your data grid
3) Create entries in your web.config and IIS metabase to support your new Httphandler for .xls files

public void ProcessRequest(System.Web.HttpContext context)
{
DataGrid Grid = new DataGrid();
StringWriter sWr = new StringWriter();
HtmlTextWriter hTw = new HtmlTextWriter(sWr);
context.Response.Clear();
context.Response.Buffer = true;
context.Response.ContentType = "application/vnd.ms-excel";
context.Response.AddHeader("Content-Disposition", "attachment; filename=spreadsheet.xls");
//whatever little method you put in to get your spreadsheet data out of the Database here:
Grid.DataSource = MyExcelData.Get(context);
Grid.DataBind();
Grid.RenderControl(hTw);
context.Response.Write(sWr.ToString());
context.Response.End();
}

Schemas for ASP.NET controls and Intellisense Department:

If you look here (take off the "2003" for VS.NET 2002):

C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\Packages\schemas\xml

you will see a bunch of schemas. If you look at the ASP.xsd schema, you'll see that for each ASP.NET server control available, there is a corresponding <xsd:element> definition in the schema; and for each property of a control, there is a corresponding <xsd:attribute> element (some complex properties like collections are also nested as elements).

There is a complete table and information about the VS.NET Intellisense schema in the MSDN documentation. To provide Intellisense support for a control that you have authored, you provide your own schema for the control's definition. You can easily create a new XSD schema and put it in the same directory as the asp.xsd schema. Once it is there, complete with all the necessary definitions, you can apply it to the WebForm where your control will be used by adding an "xmlns" atttribute to the <body> element, very much like what is done on a Mobile Web Forms page to enable intellisense support for Mobile controls. The syntax is:

<body xmlns:dtntsky="urn:http://schemas.yourname.com/AspNet/WebControls">

The syntax above assumes that your custom control will have the tag prefix of "dtntsky". Then, in the HTML view of your WebForm page, you can drag and drop your custom control from the Toolbox and it will be fully supported by the VS.NET Intellisense engine!

Well, it looks like my Martini is still cold if I hurry, so I think that about covers my rant for this time. Cya!

Dr. Dexter Dotnetsky is the alter-ego of the Eggheadcafe.com forums, where he often pitches in to help answer particularly difficult questions and make snide comments. Dr. Dotnetsky holds no certifications, and does not have a resume. Always the consummate gentleman, Dr. Dotnetsky can be reached at youbetcha@mindless.com.  Dr. Dotnetsky's motto: "If we were all meant to get along, there would be no people who wait for all the groceries to be rung up before starting to look for their damn checkbook."