Scott Hanselman

Where's Juval Lowy?

June 16, '03 Comments [5] Posted in Web Services | TechEd | Speaking
Sponsored By

One of my heros (not cuz he can code, but boy, can he drink!) is Stephen Forte...he stole one of the Flat Juval Lowy Software Legends standups at TechEd (I was going to help, but I wimped out) and proceeded to take it on a whirlwind trip around Texas, including some of the nicer bathrooms...anyway, Stephen's put the pictures up, enjoy.

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

Getting the Line Number and File Name from C#

June 12, '03 Comments [5] Posted in Web Services
Sponsored By

Someone wanted to know what the equivalent "preprocessor macros" in C# are for __FILE__ and __LINE__.  They watned to log the current file name and line number.  Note that the "1" as the first parameter to the StackFrame constructor tells it to skip ONE frame up the stack, while the true tells it to capture the file and line info.

[STAThread]
static void Main(string[] args)
{
     ReportError("Yay!");
}

static private void ReportError(string Message)
{
     StackFrame CallStack =
new StackFrame(1, true);
     Console.Write("Error: " + Message + ", File: " + CallStack.GetFileName() + ", Line: " + CallStack.GetFileLineNumber());
}

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

A Test of Google and Blogs: Selling my wife's car

June 12, '03 Comments [0] Posted in Musings
Sponsored By

This is not really technical or .NET related, but hey.  The signal-to-noise ratio is still high around here, eh? :)

So, my wife bought herself a Honda Civic Hybrid, as previously posted, and we need to sell her '97 Mitsubishi Mirage DE Coupe.  I suppose I could post adds on Vehix.com and http://www.oregonlive.com or <gasp> the newspaper.   But, I could also (possibly) take advantage of the power of Google, Weblogging and Keven Bacon and post the link here: http://www.computerzen.com/carforsale

Then, I sit back and hope that this thrilling blog post is linked to furiously, driving my site up the Google Page Ranks system to the point where ANYONE in Oregon who even THINKS, "Used Cars Oregon," "Good Used Car Oregon" or "Mitsubishi Oregon" will be magnetically sucked into my world and compelled to purchase.

Updates on this crucial experiment as the queries pour in.

Or, could I just use the Nickel Ads...

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

Figuring out which DLLHost.exe belongs to which COM+ Application

June 11, '03 Comments [4] Posted in Web Services
Sponsored By

I wanted to find out what is inside of a particular DLLHost.exe.   I went into Component Services and used "View|Status" do see the PIDs of each COM+ Application which I can then correlate to a PID in Task Manager.  Shouldn't there be a COM+ Explorer/Spy/Info Application for this, or did I miss it?

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

"Parsing a culture-aware DateTime" or "Avoiding InStr"

June 11, '03 Comments [2] Posted in Web Services | Internationalization
Sponsored By

Say you've a black-box application that you can't change that is culture-ignorant and returns a date as a string that looks like this:

6/11/2003 1:56:31 PM

but your client wants it output like this

11-Jun-03 01:56:31 PM

Sometimes folks ask me "What's the best way to parse a Date string in .NET?"  Often they are old school VBA-type folk and they are really saying "I'm going to use InStr() to parse this date unless you stop me."

So, here's a better way, IMHO.  I believe in avoiding Mid$, InStr, strstr, etc...it's just not my business to parse strings.  This is, of course, not the only way, but a possible way.  (Certainly the CultureInfo should be cached, things could be better localized, etc):

System.IFormatProvider format = new System.Globalization.CultureInfo("en-US", true);
DateTime lastLogin = DateTime.Parse(Session["lastSignOn"].ToString(),format);
lblLastLogin.Text = String.Format("Your last login was: {0}", lastLogin.ToString("dd-MMM-yy hh:mm:ss tt"));

Note that we know we are getting a the string as a U.S. formatted date time, we pass in our CultureInfo object that implements IFormatProvider to DateTime.Parse, then pass it our custom Format String to the new DateTime object's ToString(). 

This is the kind of higher level layer of abstraction that allows me to focus on business and avoid work.  Parsing DateTimes is administrivia...it's lame-o work.  The Marketects at Microsoft say "Do more with less" but I prefer my own saying "Do more business, do less work."

Put it down sir...step away from the manual string parsing code...no need for strstr() here...

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.