Scott Hanselman

Hanselminutes Podcast 41 - WS-*

November 17, '06 Comments [1] Posted in Podcast | Web Services
Sponsored By

My forty-first Podcast is up.  In this one, Carl and I talk about some of the underlying specs that make up what everyone calls "WS-star". It's a confusing bunch of specs, and I hope I explain it correctly as I think it is a useful thing for folks to know.

We're listed in the iTunes Podcast Directory, so I encourage you to subscribe with a single click (two in Firefox) with the button below. For those of you on slower connections there are lo-fi and torrent-based versions as well.

Subscribe: Feed-icon-16x16 Subscribe to my Podcast in iTunes

Links from the show are also always on the show site, although this show had no links to speak of. Do also remember the archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Our sponsors are CodeSmith Tools, /nsoftware and the .NET Dev Journal.

There's a $100 off CodeSmith coupon for Hanselminutes listeners - it's coupon code HM100. Spread the word, now's the time to buy. This coupon is good for the CodeSmith Professional With 1 Year Premier Support option.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

  • The basic MP3 feed is here, and the iPod friendly one is here. There's a number of other ways you can get it (streaming, straight download, etc) that are all up on the site just below the fold. I use iTunes, myself, to listen to most podcasts, but I also use FeedDemon and it's built in support.
  • Note that for now, because of bandwidth constraints, the feeds always have just the current show. If you want to get an old show (and because many Podcasting Clients aren't smart enough to not download the file more than once) you can always find them at http://www.hanselminutes.com.
  • I have, and will, also include the enclosures to this feed you're reading, so if you're already subscribed to ComputerZen and you're not interested in cluttering your life with another feed, you have the choice to get the 'cast as well.
  • If there's a topic you'd like to hear, perhaps one that is better spoken than presented on a blog, or a great tool you can't live without, contact me and I'll get it in the queue!

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Downloading Vista RTM

November 17, '06 Comments [16] Posted in Reviews | Tools
Sponsored By

Only 18 minutes left. I'm downloading Vista off of MSDN right now at a speedy 2 megs a second.

I've been running RC2 on my main machine at home since it came out and I've had a MUCH better experience than RC1.

My RC1 experience was very Beta 3, shall we say, and it kind of soured me.

However, I got to play with RTM on a few Microsoftie's machines at TechEd Europe last week, and my own experience with RC2 and ReadyBoost (using an Apacer Handy Steno) has been stellar. Only one blue screen in the last three weeks, and that was an ATI Display Driver bug.

I'm hoping to upgrade over RC2 (ya, I know, that's not very clever, but I'll try it if it's possible, as I REALLY don't feel like paving my machine again this year) and I'm wondering what order I should do things in.

I think I will:

  • Remove all things Office 2007 Beta 2 TR from my current Vista RC2 installation
  • Upgrade to Vista RTM
  • Upgrade to the Beta ATI Drivers for Vista RTM (Catalyst 8.31.100)
  • Install Office 2007 Professional
    • I'll skip the other apps like InfoPath, OneNote, and Visio, until I hear that they've got this whole product key thing fixed. (Right now, even though a product key is supposed to allow 10 activations (and really should be 10 PCs) it only allows one application!)

Sound like a plan? 

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Making the ASP.NET Mobile Controls render RTL languages

November 17, '06 Comments [4] Posted in ASP.NET | Internationalization
Sponsored By

When you're rendering HTML for an Arabic or Hebrew speaking audience (or Farsi, or Divehi, or Urdu, or Syriac) you usually want to change the direction of the entire page, and that's done by adding dir="rtl" to a containing element of your page, typically the HTML outer element if you want the scrollbar to switch from the left to the right. RTL, of course, means Right To Left, as these languages are typically read right to left.

In ASP.NET 1.x, this was difficult programmatically, necessitating the BODY or HTML tag being runat="server" as you went hunting for it and manually added the dir="rtl" attribute yourself. I talked about this on the blog three years ago.

It gets a little easier in ASP.NET 2.0 with the addition of the ContentDirection enumeration/property that's added to the Panel and WebPart controls.

However, if you're working with the MobileControls, it appears to be quite a bit harder, as the whole "form" metaphor changes. The Mobile stuff in ASP.NET has the notion of multiple "forms" per page where only one is active. It is that active form that does the actual rendering of the <html> element.

That means even if you have "<html xmlns="http://www.w3.org/1999/xhtml">" in your ASPX markup, you might end up with just <html> because it is the mobile:Form control that does the rendering via a PageAdapter that inherits from MobileTextWriter.

The mobile stuff in ASP.NET is very powerful, but very obtuse. I wanted to add dir="rtl" programmatically, but there's no support for custom attributes on a mobile:Form, and the Alignment="right" attribute is semantically different from dir="rtl."

Here's a page with Hebrew on it that has dir="ltr," which is also the default if you include no dir= attribute. Notice that the there are three labels for Account Name, Number, and Amount, and the labels that are within strings that include numbers have the labels on the RIGHT with the colons (:) within the label to the LEFT of the label.

That is, NUMBER COLON LABEL.

While the line without numbers, or more specifically with English included has the Hebrew labels with a colon to the right.

That is LABEL COLON ENGLISHWORD.

This is because the browser, independent of dir= attribute (or lack of one) is trying to "do the right thing" with this mixed content page (that happens to be Unicode). You can override this behavior with markup like dir= or with CSS styles like unicode-bidi: bidi-override or unicode-bidi: embed. More details on that are in the very good W3C I18N FAQ on CSS vs. Markup for BIDI (BiDirectional) support. In this post, I'm just talking about markup.

I tried to do this:

this.ActiveForm.CustomAttributes.Add("dir","rtl")

but I got this funny error message. Why funny you ask? Because it's telling me that I can't set dir="rtl" but if you do a view source (or just notice where the scrollbar is!) you'll see that it DID in fact successfully apply dir="rtl". 

This error goes away if I add this to my web.config.

<mobileControls cookielessDataDictionaryType="System.Web.Mobile.CookielessData" allowCustomAttributes="true"/>

However, the CustomAttributes bag isn't the way to effectively manipulate the rendering of the mobile controls. 

Instead, I needed creating my own PageAdapter, specifically a DirectionAwareHtmlPageAdapter:

   1:  namespace Corillian.Web.Mobile
   2:  {
   3:      public class DirectionAwareHtmlPageAdapter : System.Web.UI.MobileControls.Adapters.HtmlPageAdapter
   4:      {
   5:          public override void RenderForm(System.Web.UI.MobileControls.Adapters.HtmlMobileTextWriter writer, System.Web.UI.MobileControls.Form form)
   6:          {
   7:              writer.BeginFile(this.GetFormUrl(form), "text/html", this.Page.Response.Charset);
   8:   
   9:              //Added by me to support RTL - sucks!
  10:              writer.WriteBeginTag("html");
  11:              if (Corillian.Voyager.Web.Globalization.CurrentCulture.IsRightToLeftCulture(Thread.CurrentThread.CurrentUICulture.Name))
  12:              {
  13:                  writer.WriteAttribute("dir", "rtl");
  14:              }
  15:              writer.Write(System.Web.UI.MobileControls.Adapters.HtmlMobileTextWriter.TagRightChar);
  16:   
  17:              form.RenderControl(writer);
  18:              if (this.Device.RequiresDBCSCharacter)
  19:              {
  20:                  writer.Write("<!--\u3000-->");
  21:              }
  22:              writer.WriteEndTag("html");
  23:              writer.EndFile();
  24:          }
  25:   
  26:      }
  27:  }

This kind of sucks, because the only CUSTOM code is between line 9 and 15. The rest is copy/pasted directly out of HtmlPageAdapter using Reflector. I really think the mobile guys (and the whole ASP.NET team) should have considered the need for dynamically changing page direction for both mobile and desktop HTML. Perhaps this adapter technique is what they recommend, or perhaps there's a hidden or simpler way that I haven't figured out yet. If so, I'll post that and retract all this silliness...but until then...

You'll notice the call to a custom method called "IsRightToLeftCulture." I couldn't find anywhere in the Globalization namespace where one could just ASK a CultureInfo object if it referred to a RTL or LTR language. I know this was the case in .NET 1.1, and I'm 99% sure it doesn't exist in .NET 2.0 either. I'd love to be told otherwise.

UPDATE: I can use System.Globalization.CultureInfo.CurrentUICulture.TextInfo.IsRightToLeft() in .NET 2.0 so there's no need for this function under 2.0.

So, here is this little gem, but what price my immortal soul?

   1:  /// <summary>
   2:  /// Returns true if the supplied culture (or its parent) is read from Right-to-Left
   3:  /// </summary>
   4:  /// <returns>True if the supplied culture (or its parent) is read from Right-to-Left</returns>
   5:  public static bool IsRightToLeftCulture(string culture)
   6:  {
   7:      //Only look at the parent culture.
   8:      string myCulture = culture.Split(new char[]{'-'})[0];
   9:      switch (myCulture)
  10:      {
  11:          case "ar":        //Arabic
  12:          case "fa":        //Farsi
  13:          case "div":        //Divehi
  14:          case "syr":        //Syriac
  15:          case "he":        //Hebrew
  16:          case "ur":        //Urdu
  17:              return true;
  18:      }
  19:      return false;
  20:  }

Now that I have this new PageAdapter, I need to tell the world about it by editing my web.config:

<mobileControls cookielessDataDictionaryType="System.Web.Mobile.CookielessData" allowCustomAttributes="true">
    <device name="DirectionAwareHtmlDeviceAdapters" inheritsFrom="HtmlDeviceAdapters" pageAdapter="Corillian.Web.Mobile.DirectionAwareHtmlPageAdapter,App_Code"/>
</mobileControls>

Note the Assembly Qualified Name (QN) in the pageAdapter attribute. See how the ClassName,AssemblyName uses "App_Code" for the assembly name? That's because my DirectionAwareHtmlDeviceAdapter.cs file is in my App_Code directory. That's one of the well-known directories that automatically gets compiled when there's a .cs file in it. The assembly that's generated is App_Code.dll. A little confusing. Alternatively, I could have put the class in a separate and more manually-compiled assembly and referenced it from there.

Now that the dir="rtl" is added to the HTML element the whole page renders correctly with the labels and all page elements not only right aligned, but rendered right-to-left. The direction changes dynamically based on the browser's Accept-Language HTTP Header.

Thanks to Patrick Cauldwell and Travis Illig for their help debugging today!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

How to convert a text file with a specific Codepage to UTF-8 using Visual Studio .NET

November 15, '06 Comments [6] Posted in Internationalization
Sponsored By

A partner recently sent me a RESX (.NET Resource) text file in Hebrew for a project I'm working on. When I opened it, it looked really bad, as seen in the screenshot below.

I assumed this was a classic ANSI vs. UTF-8 problem, so I tried to do a quick conversion within Notepad2, but that resulted in nonsense East Asian characters from all over:

This means that the original file was in fact in ASCII, but just not using an English codepage. I've talked a little about codepages in the Hanselminutes Podcast on Internationalization in the past and regularly point folks to the Joel on Software article on Internationalization.

In a nutshell, a codepage is a "view" that someone can use to look

Ordinarily, I recommend that everyone (including Israelis) use Unicode/UTF-8 to represent their Hebrew characters, however, a lot of folks who write Hebrew use the Windows 1255 codepage for their encoding. (BTW, go here, scroll down, and bask in the glory of this reference site.)

So, how do I convert from one codepage to another, or in my case, from Hebrew 1255 to UTF8?

We start with Visual Studio.NET.

  • From the File menu, select Open to bring up the dialog. Note that you'll have to select a file before the Open button is un-grayed.
  • Select the tiny down-arrow on the right side of the Open button and select "Open With..."
    • -5 points for obscure UI design here
  • Next, select "Source Code (Text) Editor with Encoding." The With Encoding part is crucial, otherwise the next dialog won't appear.
  • From the Encoding Dialog, select the source document's encoding - in my case, that's Hebrew 1255.
    • -10 points for obscure UI design here.
  • At this point the document should appear correctly in Visual Studio.NET. Now, reverse the process by selecting File|Save As and clicking the tiny down arrow on the Save button, and selecting both the desired Encoding and Line Endings.

Now you've successfully normalized your document to UTF-8, and it should be usable as a RESX file or whatever you like. Here's that same document loaded into Notepad2.

And it was Good.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Best Outlook 2007 Improvement - Include Calendar

November 15, '06 Comments [6] Posted in Reviews
Sponsored By

Sometimes when you download multi-gig ISOs and have trouble installing, you look for little features that "make it all worthwhile." Little usabilty stuff, you know.

Everyone's raving about the Ribbon interface, and the Outlook "To-Do Bar" but my choice for the best new feature in Office, and Outlook in particular?

Check out the "Include" section of the Outlook New Message Ribbon...this makes it all worthwhile. It's bloodly brilliant, and it's about time. Click "Business Card" and you can add your VCard in one click. Click Signature and you can add any of your email sigs in replies or mesages where it was removed.

And the very best option? Include Calendar - a flexible little item that lets you include not only an ICS attachment with your free time, but also an HTML rendered schedule with your Availability and/or Details.

Sure, we all wish there was a cross-platform universal Free/Busy service, but until Google does it ;) we have this very clean, elegant and simple solution to one of life's daily irritations. Fabulous.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.