Code Archaeology

Define: Archaeology

A discipline involving the study of the human past through its material remains.

This is probably not an uncommon scenario:

  • You have an outdated project (or project plan)
  • You have some source code (may be in different branches in your source control)
  • You have some old emails about what various people needed
  • For some reason (low priority, budget, time), things were never done
  • You have a list of players who have left the project / company / industry / country

Your task, is to resurrect the project and make it work (again):

I was looking for a word to describe this special branch of Computer Science discipline.  And I think I've found it. 

Archaeology.

In my words, a study of the remains of ideas that were left in the system, and trying to reconstruct the past to work out a picture for the present and the future.

System.Runtime.InteropServices.COMException when opening a visual studio web project

I'm in the middle of installing everything to get my new laptop (still not working right) , and came across a problem where I couldn't open a particular web project in the solution.

"System.Runtime.InteropServices.COMException"

First thing I did was opening the project file in notepad and grab the project type guid:

{349c5851-65df-11da-9384-00065b846f21} - Ah ha!  Web Application Project

There's a few things you need to open this project on Vista:

1. You'll need IIS with IE6 Metabase and IIS 6 configuration compatibility

image

2. Run VS.NET as administrator

3. Find out the project's

Alternatively, you can install VS.NET 2008 SP1 and the messages will be a bit more friendlier.

image

 

jliu

Sharing a little gem - ASP.NET Javascript String.format

When you are working with ASP.NET 2.0, Microsoft injects quite a bit of Javascript framework stuff.  Most ASP.NET developers don't dive into these libraries and thus never know the gems that Microsoft has added in their Javascript framework.

I'm just going to share a little gem today, Microsoft has implemented a full version of the String.format in Javascript - in the same style as the .NET counterpart.

So in Javascript, you can do:

 

String.format( "{0:d}", new Date() );

or

String.format( "{0:c}", 100 );

Do watch out these values are localized to your current culture - whether it's [en] or [en-us] or [en-au], these are set in your browser's settings.

Have fun!

jliu

HTML map and area tags not working for FireFox

Here was an interesting problem, what was wrong with the following code, which works fine in IE but not in FireFox

<map id="mymap">
<area ... />
<area ... />
</map>

<img usemap="#mymap" ...>


It appears that FireFox doesn't understand the id attribute and the name attribute is required.  According to W3C recommendations, http://www.w3.org/TR/REC-html40/struct/objects.html#adef-usemap the usemap attribute should match the name attribute of the map tag.

Try this instead:

<map id="mymap" name="mymap">

Customizing CSSLink and ScriptLink for public Sharepoint site

MSDN has quite a thorough topic on optimizing a Sharepoint Server for public facing site:

http://msdn.microsoft.com/en-us/library/bb727371.aspx

I would just like to add a few more points and share some thoughts on our experiences of customizing for performance in addition to this guide.

  1. Design your Sharepoint website with performance in mind.  If you had it as an after thought and think "ooh, I'll just add performance bits at the end", then your options are far more limited.  Not to mention the extra testing time you'll need.  If you are in this situation, I'd say just stick with the caching options.
  2. Most visitors to a public facing site would be anonymous users - in fact, only a very small percentage of people may actually want to modify the website.  So switch on anonymous login and start your optimizations there
  3. The easiest bits to set up are the caching options for Sharepoint.  Sharepoint Server 2007 provides 3 means of caching:
    1. Page Output Caching - this is basically ASP.NET output caching, wrapped within Sharepoint.  Follow the discussion in the article above will get you sorted.  This has the biggest performance improvement for large amount of anonymous visitors.
    2. Object Caching - this is Sharepoint caching recently accessed object's properties (and lists) so that Sharepoint doesn't have to re-access them from Database.
    3. Binary Large Objects (BLOB) caching - this is Sharepoint caching large objects that are otherwise stored in the database on a file server.  Things like pictures, javascript files, audio, SilverLight, Flash, movies, etc.  This has to be set via the web.config (defaults to 10 GB of space allocated for this).
    4. OK, these are the easy stuff - read the MSDN link if you need instructions to set this up.
  4. The article further discusses rendering core.js for only authenticated users.  This takes a bit more effort to figure out.
    1. The idea behind the RegisterCoreWhenAuthenticatedControl is good, but proper implementation requires understanding of how ScriptLink works.
    2. A ScriptLink control can be specified on the page at one point, and subsequent ScriptLink.Register will add more scripts to be added at that point.
    3. A ScriptLink control will always register core.js unless it is in minimal mode
    4. To create a ScriptLink in minimal mode, create one in the markup without the name attribute (yes.  this is really cryptic - here's why you need Reflector)
    5. <Sharepoint:ScriptLink runat="server"/>
    6. Follow by the control specified in the article:
    7. <NoCoreLoad:RegisterCoreWhenAuthenticatedControl runat="server"/>
  5. We took the idea a bit further and thought if we can get rid of the core.js file, how about get rid of the core.css file too, or in fact, anything.  What we need is a wrapper container of some sort.
    1. There are two related classes for CssLink
    2. The CssRegistration class adds CSS files to the Sharepoint context
    3. The CssLink control renders all CSS files added to the Sharepoint context
    4. The CssLink can have additional DefaultUrl and AlternativeUrl specified,  but it will always render the core.css file.  There is no minimal mode
    5. The way we use is to create a wrapper container for CssLink

      public class AuthenticatedPanel : Panel
      {
          protected override void Render(HtmlTextWriter writer)
          {
              if (HttpContext.Current.Request.IsAuthenticated)
              {
                  base.Render(writer);
              }
          }
          public override void RenderBeginTag(HtmlTextWriter writer)
          {
              //disable rendering <div>
              //base.RenderBeginTag(writer);
          }
          public override void RenderEndTag(HtmlTextWriter writer)
          {
              //disable rendering </div>
              //base.RenderEndTag(writer);
          }
      }
    6. <AuthenticatedPanel>
          <CssLink runat="server"/>
          <CssRegistration runat="server ... />
      </AuthenticatedPanel>

      <link rel="stylesheet" type="text/css" href="...path" />
  6. I like the AuthenticatedPanel that we created a lot more than the RegisterCoreWhenAuthenticatedControl - it is far more flexible in terms of the control we get on what gets rendered on the page at the end.

Good luck!