Wednesday, June 22, 2011

Grok talk on NuGet 6/22/2011 1800 EST

I will be giving a grok talk about “NuGet” (the Visual Studio 2010 extension) to the Dayton .NET Developers Group. If you’re in area, I invite you to come down. (Don’t forget to point and laugh Winking smile)

Here is my slide deck.

When: June 22, 2011 at 6pm EST

Where: 711 East Monument Avenue, Suite 101 in downtown Dayton, OH

Wednesday, May 18, 2011

jQuery Boxy content will not display / show

Every so often I’ve used the jQuery plugin called “Boxy”

Today I ran into an issue: The content I gave boxy would not display / show on the page.

Here was my incorrect code:

   1: new Boxy("Justin Kohnen is the best programmer ever!", 
   2: { 
   3:     closeText: "close"
   4:     , title: "Shout out."
   5:     , unloadOnHide: true
   6: });

After reading the fantastic manual I found: (underline added for emphasis)

The content passed to the constructor can be any valid parameter to jQuery's $() function - a DOM element, an HTML fragment or another jQuery object. Whatever is provided will be set to display: block and have the class boxy-content added prior to its insertion within the dialog.

The key here was raw text is not a “valid parameter to jQuery’s $() function.”

So my fix is simply to wrap my text in a <p> tag. Making it an HTML fragment

Here is the corrected code:

   1: new Boxy("<p>Justin Kohnen is the best programmer ever!</p>", 
   2: { 
   3:     closeText: "close"
   4:     , title: "Shout out."
   5:     , unloadOnHide: true
   6: });

Simple, but silly problem.

I hope this helps someone.

Cheers.

Tuesday, April 12, 2011

Installing and Uninstalling a Windows Service from the Command Line

I develop a windows service every now and then. I always have to dig up the install and uninstall commands. I figured I would post it for all.

Install

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installutil /LogToConsole=true "<path_to_service_exe>"

Uninstall

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\installutil /u "<path_to_service_exe>"

Make sure to replace <path_to_service_exe> with what works for you.

If you’re on Win7 or Win2008 Server, you’ll need to start your Command Prompt as an administrator.

Cheers.

Thursday, March 3, 2011

Tracking a browser’s Time zone Offset in ASP.NET

Just the other day I was required to display a website’s dates in a user’s local time.

The solution I came up with was based on getting the time zone offset from the user’s browser using JavaScript, Storing that value into a cookie, then converting the cookie value to the a number I’m used to working with (i.e. negative hours), then I can convert UTC dates to the user’s local time zone by adding the Offset.

All of this magic happens for me in my website’s base page. (All my pages inherit from my base page)

   1: public class BasePage : System.Web.UI.Page
   2: {
   3:     private const string mTimeZoneCookieName = "TZOS"; // Time zone Offset
   4:  
   5:     protected override void OnPreInit(EventArgs e)
   6:     {
   7:         setCookieForTimezoneOffset();
   8:     }
   9:  
  10:     private void setCookieForTimezoneOffset()
  11:     {
  12:         if (Request.Cookies[mTimeZoneCookieName] == null)
  13:         {
  14:             ClientScript.RegisterStartupScript(GetType(), "Timezone",
  15:             string.Format(
  16:             @"<script language=""javascript"">document.cookie = ""{0}="" + new Date().getTimezoneOffset(); </script>",
  17:             mTimeZoneCookieName));
  18:         }
  19:     }
  20:  
  21:     public int TimezoneOffset
  22:     {
  23:         get
  24:         {
  25:             return getTimezoneOffset();
  26:         }
  27:     }
  28:  
  29:     private int getTimezoneOffset()
  30:     {
  31:         int returnValue;
  32:         returnValue = (Request.Cookies[mTimeZoneCookieName] == null) ? 0 : Convert.ToInt32(Request.Cookies[mTimeZoneCookieName].Value);
  33:         // JavaScript returns 300 if the offset is -5 offset so I convert the number
  34:         return (returnValue / 60) * -1; 
  35:     }
  36: }

The only catch is: The very first time a user loads any page the times will be GMT/UTC after a single postback everything is as right as rain. On way this could be corrected is by tweaking the “Timezone” start up script a bit to force a refresh. (And that’s just one solution, I’m sure you can come up with another.)

I hope that helps someone.

Cheers.

Monday, February 28, 2011

My TortoiseSVN Global ignore pattern

Some files shouldn’t be committed into version control. Usually things generated by the computer (i.e. exe’s, dlls, etc.) and user specific files (i.e. *.suo, *.user, etc.)

Here is the global ignore pattern I use for TortoiseSVN to exclude such files.

<pattern>
*.o *.lo *.la *.al .libs *.so *.so.[0-9]* *.a *.pyc *.pyo *.rej *~ #*# .#* .*.swp .DS_Store _ReSharper.* *.resharper *.suo *.user bin obj
</ pattern>

Hope it helps someone.

Friday, October 29, 2010

Computing First and Last Day of the Month

I stumbled across this the other day and I thought it was so slick I would share.

This example computes the DateTime for both the first and last day of the current month.

var monthStartDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
var monthEndDate = start.AddMonths(1).AddDays(-1);

You can take the range even further by changing the “AddMonths” number.

Pretty slick.

Saturday, October 9, 2010

Issue: IIS7 “Reports” folder is requiring Windows Authentication

I’ve been working on a ASP.NET project that contained a sub folder call “Reports.” Oddly, every time I tried to browse to it under IIS7 I would get prompted with a “Windows Authentication” dialog.

I had never programmed this, and couldn’t figure out why it was required.

Turns out, the issue was with having SQL Server Reporting Services installed. SSRS by default uses the “Reports” virtual directory under port 80 as it’s Report Manager URL.

After I changed the “Report Manager URL” within the “Reporting Services Configuration Manager” everything was right with the world again.

I just thought I would share this with everyone in case someone else runs into the problem.

Details:

I’m using IIS7 and SQL Server 2008