advanced web statistics

Set Silverlight Startup Page

In sandboxing Windows Phone 7 recently I came across the need to change my startup page.  The reasoning for this is simple: I have a core of the work completed and I want to sandbox a data call before I implement in the actual application.  With conventional web projects this is as easy as right-clicking the file you want to and click 'Set As Start Page'. With the Windows Phone 7 SDK this luxury does not exist.

There is however a way to accomplish this with a little bit of code.  Simply open up your projects App.xaml.cs and implement an Application_Startup method.

private void Application_Startup(object sender, StartupEventArgs e)
{
    RootVisual = new SandboxPage();
}

SandboxPage is the name of my XAML page in this example. Here we simply set the RootVisual to an instance of our new page.

The second piece to this is registering this startup method in the App constructor a la:

public App()
{
    Startup += Application_Startup;
}

This doesn't necessarily apply to Windows Phone 7.  General Silverlight.

Easy.

kick it on DotNetKicks.com

Hello Windows Phone

Today the Community Technology Preview release of Visual Studio 2010 Express for Windows Phone 7 was released. For those not in the know, this release provides 100% compatibility with the final version of Visual Studio 2010.

You can get it here: Visual Studio 2010 Express for Windows Phone 7

I have been interested in and writing XNA for a couple of months now and will start posting more regularly thanks to this new addition.

Stay tuned!

kick it on DotNetKicks.com

Dynamically Insert Language ISO Code in Sitecore Url

In working with localizing a Sitecore CMS solution recently I came across an interesting requirement: analytics (SEO optimization by region).  I was handling Sitecore localization by adding supported languages and creating localized versions of each content item.  The wrinkle was that I needed to now add a language prefix to all the urls on the site so they could get indexed appropriately for each region.  To make it even more complicated, I had to deal with hard-coded urls that weren't driven by the CMS.  I thought I was going to have to create multiple sites within Sitecore for each language, duplicate content, etc...  It turns out that it was much easier than this.

In a Sitecore web.config you'll find a linkManager section. This will handle much of the heavy lifting for you. There is one setting that you need to pay attention to (2 if you aren't using IIS 7).

The first (and most important) is the languageEmbedding setting. In a site that is in one language you should set to "never". A site that may have one or two localized pages here and there set to "asNeeded". In my case, a full-blown localization effort, this should be set to "always".

If you aren't using IIS 7 you will need to set the setting for addAspxExtension to "true".

    <linkManager defaultProvider="sitecore">
      <providers>
        <clear />     
          <add name="sitecore" type="Sitecore.Links.LinkProvider, Sitecore.Kernel"
          addAspxExtension="true"
          alwaysIncludeServerUrl="false"
          encodeNames="true"
          languageEmbedding="always"
          languageLocation="filePath"
          shortenUrls="true"
          useDisplayName="false" />
      </providers>
    </linkManager>

Sitecore CMS will now take care of the url rewriting!  Easy.

For those you like me that have pre-defined navigation requirements (i.e. not driven 100% by the CMS) there is one more step to take to accomplish url prefixing.  Take a link such as:

<a href="/Foo.aspx">

To get a url that looks like http://www.foo.com/de-DE/foo.aspx you simply need to write a little bit of "yellow code".

<a href="/<%= Sitecore.Context.Language %>/foo.aspx">

Easy.

kick it on DotNetKicks.com

Problem Deploying MVC Applications on IIS 5.1 or IIS 6?

I know what you are thinking, "Who uses IIS 5.1 or IIS 6 these days?"  Believe it or not, some environments still use these and I had been pulling my hair out trying to deploy an MVC application to an IIS 5.1 server. The application works in production and wasn't working locally. Nothing had changed aside from some minor View refactoring. A couple of hours later I thought back to an Ektron project that required URL-rerouting and then it dawned on me: "IIS is checking to make sure that the file exists".

I opened up IIS, drilled down to my application, and followed these steps:

  1. Right-click application (or virtual directory)
  2. Click 'Properties'
  3. Click 'Home Directory' if application ('Virtual Directory' if virtual directory)
  4. Click 'Configuration' button
  5. Click 'Add' button
  6. Executable: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll
  7. Extension: .*
  8. Check 'All Verbs' if it isn't already (it should be)
  9. Uncheck 'Check file exists'
  10. Click 'OK'
  11. Click 'Apply'
  12. Click 'OK'
Dear Diary. Jackpot.

kick it on DotNetKicks.com

jQuery Data Method is the Business

<3 this little jQuery gem

$(document).ready(function() {
    $('#button').data('Data', { Message: 'sup foo?', Email: 'asdf@asdf.com' });

    $('#button').click(function() {
         var data = $(this).data('Data');
         alert(data.Message + '\n' + data.Email);
    });
});

<input type="button" id="button" value="clickie" />

jQuery data() method result

Easy.

kick it on DotNetKicks.com

Generic jQuery Function to Remove CSS Classes

I've been using a lot of jQuery lately in a new project and am falling in love with it!  It is a wonder why I have never used it before but am glad I was kind of forced to learn it ;)

As with anything new there is a bit of a learning curve.  The application I am working on boasts a large number of tabs for different sections of the site.  One of the requirements is to toggle the "active" tab via CSS class.  Easy right?  This was easy to do in vanilla JavaScript so it should be super-easy to do with jQuery.  It is!

$('#FooItem1').removeClass('active');
$(
'#FooItem2').removeClass('active');
$(
'#FooItem3').removeClass('active');
$(
'#FooItem4').removeClass('active');
$(
'#FooItem5').removeClass('active');

That works great but there is one caveat: adding new tabs.  If the requirements of the UI changed and we were to have to add a new tab (or 6 more) then we would have to not only change the view (or in this case partial view ;) ) but also the JavaScript functions dealing with these tabs.  Since all of our tabs are UL with stylized LI's containing anchor tags I decided to create something like this:

function RemoveActiveClassFromListItemControlByID(controlID) {
   $(
"#" + controlID).children().each(function() {
   $(
this).children("a").removeClass("active");});
}

Now this isn't that generic since I have the "a" and "active" strings hard-coded.  In this case it works for us since all the tabs are the same format and all we really need is the id of the control.  This little function will enumerate the children of the control (in this case all LI's and then enumerate the A children and remove the active css class.  Simple.  To extend this to be even more generic you could do the following:

function RemoveClassNamesFromChildElementByControlID(controlID, childElement, className) {
$(
"#" + controlID).children().each(function() {
   $(
this).children(childElement).removeClass(className);});
}

Here's an example of how you could use the function above.  Let's say that you want to enumerate all children in a OL with an id of "fooList". Each children has a span tag with a css class of BAR and you want to reset all of them when a user clicks on a hyperlink.  This would be extremely simple:

<a href="javascript:(RemoveClassNamesFromChildElementByControlID('fooList', 'span', 'BAR'));">CLICK HERE</a>

Easy.  I'm really starting to love this jQuery business.

jQuery + MVC = love

kick it on DotNetKicks.com

SQL Server 2008 Save Not Permitted Dialog Box

I was creating some tables this evening in a SQL Server 2008 database this evening so that I could sandbox some MVC functionality for a current project.  I had designed the tables according to the tutorial only to find out that this wasn't the case.  I'll just log back in to SQL and make the necessary changes.  Easy.

When I added the missing column I went ahead and reordered to match the same order of the tutorial because, well; I am a little OCD at times.  I remember doing this in the past pre-SQL 2008 with no trouble.  This time I was hit with this:

Weird.  Again, I had never seen this before so I was a bit surprised.

According to SQL Server 2008 Books Online this can be caused by any of the following:

  1. Adding a new column to the middle of the table
  2. Dropping a column
  3. Changing column nullability
  4. Changing the order of the columns
  5. Changing the data type of a column

Really?  These all seem like fairly common tasks when working within a database.  As odd as this may seem (maybe there is a good reason for this?), there is a very easy fix.

From the Tools menu click on Options, expand Designers, click on Table and Database Designers.  Select or clear the Prevent saving changes that require table re-creation option.

Much better.  Back to work.

kick it on DotNetKicks.com

SQL 2008 and The Setup Failed to Read IIsMimeMap Table

Decided to install SQL 2008 recently because of it being 2009 and all.  What an adventure.  Although not near as bad as upgrading from Vista Home Premium to Vista Ultimate, it sucked pretty bad.

I downloaded the 120-day trial Developer Edition as a self-extracting executable because I didn't feel like burning a DVD / using Daemon Toolz.  The download was the smoothest part of this whole deal.

From the installer screen I chose the Upgrade from SQL 2000 / 2005 option because I have SQL 2005 Developer Edition installed so this made the most sense.  Miserable fail.  I kept erroring out when trying to install SQL Reporting Services.  The exact error(s) escape me but I remember it having something to do with authentication and the report service.  Naturally I thought to manually stop and start the service to see if there was any issue.  Good thing because manually starting the service failed.  It then dawned on me that between the time I had initially installed SQL 2005 and that very instant I had changed my Windows password.  Right-click, 'Properties' and changed it to my current password, restart the service: SUCCESS!

Now let's try upgrading again: FAIL!

After hitting the Google fairly hard I read a couple of blog entries detailing how uninstalling SQL Server 2005 entirely from the Control Panel would remedy the situation.  I tried this and received the following error when attempting to uninstall SQL 2005 Reporting Services:

Failed to read IIsMimeMap table 01

Awesome.  Have no idea what this means so I searched Google for it.  Apparently no one else does either.  There were tons of suggestions as to how to go about remedy'ing this so I tried a couple.  These solutions ranged from reconfiguring Reporting Services to uninstalling and reinstalling IIS7.  I opted to try and reconfigure Reporting Services only to find that the configuration tools no longer existed on my machine seeing as how that was successfully uninstalled before receiving the error message above.  I then tried to uninstall again and received this error message.

Failed to read IIsMimeMap table 02

Same error, different error code. Weird.

The final solution was to install each component of SQL 2005 one-by-one from Control Panel.  As crazy as that sounds it actually ended up being successful.

So, if you are getting these error messages try uninstalling each and every SQL 2005 component one-by-one and then do a clean install of SQL 2008.  It worked for me.

kick it on DotNetKicks.com

LAMP Developer Needed

Checked an e-mail account that has apparently been exluded from my main Send/Receive group in Outlook today and found this e-mail in the Junk E-mail folder.

Maybe I should use this to setup a rule...

;)

LAMP Developer Needed

I have learned a bunch of exciting things over the past couple of months but unfortunately it's proprietary and I can't blog about it!

I was never one to blog about where I work or what projects I have been working or else I'd have a ton of new entries.

kick it on DotNetKicks.com

Microsoft Office Interop Outlook & C# For Outlook Searches

I had a need yesterday to query a bunch of Outlook e-mails: 44,743 to be exact.  This was the result of a clients mailing list account being setup incorrectly and we just found out about it!  An e-mail account was setup strictly for the mailing list and it was never properly setup as an Outlook account locally.  No big deal.  When the hosting provider contacted us to clean it up I noticed that there were a BUNCH of bad e-mail addresses (Return to sender, bad account, etc...).  At first I started to click on individual e-mails, copy the bad e-mail address to a .txt file, then search that folder for the same e-mail address and delete the results.  That takes FOOOOORRREEEEVVVVEEEEERRRRRRR.  Then I realized I could dork around with Outlook via a C# console application and harvest the e-mails and output them in a sorted Excel spreadsheet.

Enter Microsoft.Office.Core and Microsoft.Office.Interop.Outlook namespaces. I decided it would be best to create a little C# console application utilizing these namespaces to search the e-mail, write a little regular expression pattern (by write I mean copy & paste one from the interwebs) to parse out e-mail addresses, and add e-mail addresses that didn't have the host name or the reply e-mail account in it to a List<string> (if it didn't already contain it!).  It was pretty easy.

First:

using Outlook = Microsoft.Office.Interop.Outlook;
using Microsoft.Office.Interop.Outlook;

I'm not going to bore you with the entire application unless you really want it.  I'll just get you to the point where you can start to do stuff with your e-mails.

Now you need to instantiate your Outlook object.

Outlook.Application application = new Application();
Outlook.NameSpace nameSpace = application.GetNamespace("MAPI");
Outlook.MAPIFolder mapiFolder = nameSpace.GetDefaultFolder(OlDefaultFolders.olFolderJunk);

It might be worth mentioning the olFolderJunk business you see there.  In the interest of time I didn't want to mess around with trying to navigate to the folder that I actually stored these e-mails in since I have a bunch of subfolders in Outlook due to using multiple accounts and a handful of rules and what-not.  So in the interest of time I moved all the e-mails to the junk folder since I could easily access it.  I think the correct syntax would be something like:

nameSpace.Folders["FOLDER"].Folders["SUB"].Folders["YOU_GET_IT"];

Moving on.  Once you finally get access to your designated folder you need to start being able to do stuff with the items in that folder.  It's as easy as enumerating the, you guessed it; MailItem objects a la:

foreach (MailItem mailItem in mapiFolder.Items)
{
   // do stuff
}

Easy.  The properties are fairly braindead as well.  MailItem Object Members

Have fun.  I'll probably use this in the future as well.

kick it on DotNetKicks.com

<< Newer Entries Older Entries >>