|
|
These blog entries are written by industry experts and leaders. We consider this content to be a good read for any software developer or web technologist.
September 2007 - Posts
-
Even if you want nothing to do with Rails you should take a look at Rails Migrations because it is the best solution I have found to such a common development problem. The problem being how to make updates to your various databases in a sane manner.
Start with the quick screencast. Then check out this nice cheat sheet.
I know a couple of people are trying to figure out how to do something like this in .NET, if I had more time I would give it a try as well.
-James

|
-
Now that I am free of the corporate firewall I am looking for more and more ways to get music online. I gave up on Rhapsody because their new client sucks and they jacked up their price. I tried last.fm but for some reason every channel I pick runs out of content in like 10 minutes. I have Sirius subscription which can be cool. (Left of Center and Bloomberg Radio are my favorite channels)
I also recently came across Radioshift which is a cool application for the Mac which lets you record internet radio and listen to it on your time. For instance I just set it up to record a show called the "Indie Rock Show" on Z106 in Bloomington. It's on sundays from 7:00-8:00PM. I have never heard of the station or the show, but I look forward to checking it out tomorrow while working.
-James

|
-
Hard to imagine, but 4GuysFromRolla.com turned nine years old this month. The first article I authored was titled, Using ActiveX Controls on Your Web Page and looked at creating an ActiveX using Visual Basic 5.0 and deploying it on a web page via the <object> HTML element. It was published on September 16th, 1998. To put it another way, I've been writing articles and FAQs and tutorials on Microsoft web technologies on, at minimum, a weekly basis, for nearly one-third of my entire life. Scary.
The site was originally started with three college buddies who covered non-web development topics, but by 2000 they had all moved on to other projects. 4Guys was sold to Internet.com (now JupiterMedia) back at the height of the dot com bubble, but I have remained the main contributor and editor for the site. Back in August of 2001 I wrote a short piece on the history of the site, which is still pertinent today seeing as not much has changed about the site since then. I keep pumping out articles every week, just like I did back in 2001.
I wonder if I'll still be doing this when 4Guys turns 10, or 15, or 25. Who knows. If you would have asked me in 1998 if I thought I'd still be writing web technology articles nine years later I would have thought the idea highly unlikely, perhaps a bit absurd. But the younger you are, the harder it is to have an understanding or appreciation of the scale of time.
In any event, it's been a great nine years and I look forward to the next nine. I hope you have found and continue to find the articles on 4Guys to be instrutive, useful, interesting, timely, and helpful.
Happy Programming!
|
-
ASP.NET ships with a variety of essential Web controls - the TextBox, the DropDownList, the GridView, and the like. While these controls are fine and dandy for simple scenarios, they quickly become obsolete for more complex ones. Consider collecting date values. The ASP.NET toolbox includes a TextBox and a Calendar control, either of which can be used independently to capture date values, but a better user interface involves a textbox integrated with a pop-up calendar. Similarly, ASP.NET's TextBox control is great for collecting plain text input, but falls short if you need users to be able to enter formatted text.
Microsoft has made it clear that they plan on including only the basic controls in the ASP.NET toolbox and have left more advanced controls to the third-party market. There are a variety of third-party ASP.NET control vendors, from small one-man operations providing a single product, to larger companies that include a suite of controls. One such vendor that I've written about before on this blog and in my Toolbox column in MSDN Magazine is Karamasoft. I recently wrote a whitepaper for Karamasoft that provides an overview of UISuite, a control suite that encompasses ten UI-related controls. The whitepaper, Let UISuite Do Your Dirty Work [PDF], showcases how quick and easy UISuite's components make building and implementing powerful user interfaces.
UISuite contains the gamut of canonical ASP.NET controls - there's a rich text editor, a menu, a date picker, and so on - but what most impressed me was the UltimateSearch component. Searching the contents of a website involves crawling and indexing content and displaying a search user interface. Microsoft provides Index Server to assist with searching a website's file system, but setting up and configuring Index Server can be challenging, especially when serving your website from a hosted environment. UltimateSearch makes adding search a breeze. Just drop the UltimateSearch assembly in the /bin directory and specify the indexing and crawling settings in a .config file and you're off and running. You don't need to register any component on the server; there's no configuration required (outside of that one .config file); you don't need to setup a Windows Service or schedule any tasks through Windows Scheduler; you don't need to have access to a database as the search index is stored in a file within your web application. In short, if you can FTP files to your website, you can use UltimateSearch.
What's more, UltimateSearch includes a Web control that you can drop onto a page to display a search user interface. With a few property settings you can enable advanced search UI features, such as auto-suggest and spell checking. No code necessary. It really is amazing how easy it is to add search to your site with UltimateSearch. Ok, ok, enough gushing about UltimateSearch.
In closing, if you are interested in learning more about UISuite or are in the process of evaluating third-party controls for your ASP.NET application, check out my whitepaper.
Happy Programming!
|
-
One of the products that my team builds that I am most proud of is IIS 7. IIS 7 is a *major* update of our web-server stack, and introduces a significantly new and improved extensibility, configuration, and administration architecture. I've blogged about some of its features in the past here and here. Doing a major re-architecture on a mature product is never easy. Doing so on one that runs more than 40% of the web servers on the Internet is especially daunting. The final product, though, is fantastic - and delivers an incredibly flexible, scalable, and robust server architecture that is going to enable us to-do really exciting things going forward. Earlier this week we shipped the RC0 build of Windows Server 2008 and IIS 7.0. You can learn more about it and download the RC0 version from Mai-lan's blog post here. IIS 7.0 Extensibility (and why it is cool) One of the major changes we made to IIS 7.0 was to make the system radically more extensible than previous versions of the web-server. This extensibility applies both to the core HTTP processing engine, as well as to the configuration system, health monitoring system, and admin tool architecture. You can now write managed .NET classes to cleanly extend all of these sub-systems. This is great from a customer perspective (since you can now replace and extend anything in the system). It also enables us to easily ship web-server extensions and additions in a very agile way on the web. Starting this week you are going to begin to see a number of really cool, fully-supported, free features start to be delivered this way. Below are a few of them available this week: IIS 7.0 FTP Publishing Service We are delivering a new modern FTP service implementation that runs on IIS 7.0. This FTP service offers a much improved administration and configuration experience (it uses the same web.config model as IIS7 and ASP.NET, and integrates into the IIS7 admin tool). It now supports FTP over SSL, as well as UTF8 and IPv6. The FTP server enables you to host both FTP and web content from the same web-site on IIS7 (just add a FTP binding to your existing web-site to enable it). It now provides support for virtual host names, which means you can host multiple FTP sites on the same IP address. It also has built-in user-isolation support, which makes it perfect for shared hosting scenarios. The FTP server's authentication system is now pluggable - which means you can add your own username/password store to manage logins. Best of all, you can use the existing ASP.NET Membership Provider model to plug-in your own credential system for logins and user management. You can learn more about the FTP Server here and download it here (x64 here). IIS 7.0 Media Pack Bit-Rate Throttling Module One of the challenges when hosting large videos and audio files on the Internet is that bandwidth costs can be expensive. What is worse is that you often end up having to pay for users to download videos that aren't fully watched. Specifically, web-servers are by default designed to download content files as fast as possible. So if a user visits your site and starts watching a 50MB video on it, the web-server will by default try and transmit the 50MB file as quickly as possible to them. If the user closes the browser half-way through watching the video, you will end up having to pay for the remaining 25MB of content they had finished downloading - but which they never actually watched. The IIS 7.0 Media Pack Bit-Rate throttler provides a much more cost-effective way to host video and audio on standard web-servers. When a browser (using a plug-in like Silverlight, Flash, Windows Media Player, iTunes, etc) requests a media file, IIS7 will automatically detect the encoding bit-rate of the file and determine how many bytes per second the player needs to receive to play it continuously. IIS7 will then "burst" enough of the content (by default 20 seconds of the video/audio file) to ensure that the client player can start playing the video, and won't ever run into a buffering delay. IIS7 then automatically slows down the file transmission to equal the encoded bit-rate (so if the video is encoded at 400kbs, IIS7 will burst 20 seconds of this, and then slow the remaining transmission to 400kbs of content). If the user closes the browser on the video while it is playing, IIS7 will automatically detect the connection was dropped and avoid sending any more of the content (saving you the remaining bandwidth costs). This module works today with Silverlight, Flash and Windows Media Player - no code changes are required in the players to enable it. You can install the IIS7 Media Pack Bit-Rate Throttler on both Vista and Windows Server 2008. You can learn more about it here and download it here (x64 here). IIS 7.0 Remote Manager Administration Tool IIS 7.0 ships with a significantly improved administration tool experience. The admin tool is entirely written in managed code (using Windows Forms), and supports remotely administering a web-server over HTTP based web-services (allowing you to use the admin tool to manage servers remotely in a hosted environment through proxy servers). The administration tool supports configuring both standard IIS settings, as well as ASP.NET ones (for example: you can use the tool to remotely manage ASP.NET membership/roles). Earlier this week we shipped a standalone installation of the IIS 7.0 admin tool that you can use to remotely manage Windows Server 2008 based IIS7 web-servers from Windows XP, Windows Server 2003, and Windows Vista client machines. You can learn more about the Remote Admin Tool and download it here (x64 here). FastCGI Support for IIS 5.1 and IIS 6.0 IIS 7.0 ships with built-in support for FastCGI - which is a high performance alternative to using CGI for web-server extensibility. Many popular web frameworks (in particular PHP) use this to integrate with web-servers. In addition to having FastCGI support built-in to IIS 7.0, this week we also shipped a FastCGI ISAPI extension that works on existing IIS 5.1 and IIS 6.0 web servers. You can learn more about the FastCGI extension here, and download it here. Summary The extensibility architecture of IIS7 is going to enable us to continually enhance and ship more features that run on top of it in the months ahead. I'll be blogging more soon about some of these additional extensions (including about a new new wickedly cool automated web deployment system that supports rolling out versioned web applications across servers - including to remote web servers, and across web-server farms). I think you are going to find IIS7 a really exciting web application server to use. To learn more about it, make sure to visit www.iis.net, and sign-up for the upcoming free IIS7 web-casts here. Hope this helps, Scott P.S. IIS7 is currently running all of the www.microsoft.com web servers (read their blog post on why they love it). 
|
-
Events are easy to add and remove when using the CLR and C#. Just sprinkle some += and -= in the right places and the runtime does the rest. Silverlight programming with JavaScript is a bit different, however, and although the addEventListener and removeEventListener appear similar to a DOM element's event registration APIs, these two methods have a twist.
As an example, let's say we wanted to listen to the MediaElement's BufferingProgressChanged event, but we want to stop listening once buffering has exceeded 50%. The following code does work:
function onLoad(rootElement)
{
var mediaElement = rootElement.findName("_media");
mediaElement.addEventListener("BufferingProgressChanged",
"onBufferProgress");
}
function onBufferProgress(sender, eventArgs)
{
// .. do something
if(sender.BufferingProgress > 0.50)
{
sender.removeEventListener("BufferingProgressChanged",
"onBufferProgress");
}
}
.. but this code will never unsubscribe from the event:
function onLoad(rootElement)
{
var mediaElement = rootElement.findName("_media");
mediaElement.addEventListener("BufferingProgressChanged",
onBufferProgress);
}
function onBufferProgress(sender, eventArgs)
{
// .. do something
if(sender.BufferingProgress > 0.50)
{
sender.removeEventListener("BufferingProgressChanged",
onBufferProgress);
}
}
When not using a quoted string to specify the event handler, you have to save the value returned from addEventListener. The return value is a token that is "just an integer value to track the order in which handlers were added for each object-event combination" (read MSDN for other subtleties in the event registration methods).
A proper unsubscribe looks like the following:
var token;
function onLoad(rootElement)
{
var mediaElement = rootElement.findName("_media");
token = mediaElement.addEventListener(
"BufferingProgressChanged",
onBufferProgress);
}
function onBufferProgress(sender, eventArgs)
{
// .. do something
if(sender.BufferingProgress > 0.50)
{
sender.removeEventListener("BufferingProgressChanged",
token);
}
}

|
-
There is no mouse double-click event on UIElements in Silverlight.
Some people think this is an odd omission. Silverlight's cousin WPF can fire a double-click event, so why not Silverlight? Even JavaScript can catch double-click events inside a web page (although in true web fashion, the exact behavior depends on the combination of browser version, operating system, and the current phase of the moon – see Jan Wolter's Javascript Madness: Mouse Events for all the gory details).
You can still detect a double click using a mouse up event handler and a timestamp - but should you? The omission of a double-click event wasn't because of a technical limitation – the omission is a deliberate design decision. Silverlight is built for the web, and many consider double-clicking on the web to be a usability no-no.
Here is what Peter Chng has to say:
Take this comment by about the new Yahoo! Photos site; the user laments about the interface requiring a double-click to open a full-size image rather than just a traditional single-click as on most other websites. (The double-click detection is done via JavaScript)
I'll admit that while I was first confused by this action, I thought little of that user's comment - I mean, how hard can it be to learn a simple action like that? But, after some more thinking, I've come to agree with the comment - breaking the pattern of how a user navigates on a website is not a good idea, even if it's done to try to make your website feel more like a desktop application.
The New York Times website includes a feature that launches a search (in a pop-up window) when you double click a word inside an article. Digital Inspiration believes this behavior is user unfriendly, while Dion thinks the feature is a bug.
You might also have noticed the only mouse button events in Silverlight are LEFT mouse buttons events. Macs don't have a right mouse button, and my guess is they never will (adding one now would be like admitting defeat). Exposing a right-click event could only invite more usability problems.
Silverlight has some wonderful potential. Just remember to innovate – don't aggravate. 
|
-
Phil dug up an old post of mine on conditional compilation, but defining a constant in web.config didn't appear to work for him. I didn't see anything wrong with his approach, so I downloaded the solution and did some spelunking.
With this page ...
<%@ Page Language="C#"
CompilerOptions="/d:QUUX" %>
...
<div>
<% #if BAZ %>
BAZ in the aspx file.
<% #endif %>
<% #if QUUX %>
QUUX in the aspx file.
<% #endif %>
</div>
...
... and this web.config ...
<system.codedom>
<compilers>
<compiler
language="c#;cs;CSharp" extension=".cs"
compilerOptions="/d:BAZ"
type="Microsoft.CSharp.CSharpCodeProvider, System,
Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />
</compilers>
</system.codedom>
... then the page behaves as if only the QUUX is defined.
To understand the scenario I added <compilation debug="true"> to the web.config. Debug settings leave behind a .cmdline file in the temporary ASP.NET files directory. The .cmdline file contains the exact commands to invoke the C# compiler, and the abbreviated form looked like this:
...
/t:library /utf8output
/D:DEBUG /debug+ /optimize- /nowarn:1659;1699
/d:QUUX
...
I went in thinking the compilerOptions would be additive, but after a smack on the forehead, I realized the compiler options in the @ Page directive override the web.config compiler options. Remove the compilerOptions attribute from the @ Page directive and BAZ becomes defined.
The behavior does seem to follow the principle of least surprise, even if it did catch us off guard.

|
-
Here is the latest in my link-listing series. Also check out my ASP.NET Tips, Tricks and Tutorials page for links to popular articles I've done myself in the past. Visual Studio ASP.NET -
Debugging Script: Dumping out ASP.NET Session Contents: Tess Ferrandez from the ASP.NET support team has an excellent post that details how to use the windbg debugger to dump out real-time information about the current state within the ASP.NET in-process session store (# of sessions, what their current timeout is, and the memory size of the objects within each session). She has a great script you can just run "as-is" in this article, as well as an in-depth discussion about how it works. Very useful if you are ever trying to figure out why your application is consuming a lot of memory, and suspect it might be session state related. -
Facebook.NET: Earlier this summer Nikhil Kothari from the ASP.NET team posted a really cool framework for developing ASP.NET based Facebook applications. You can learn more about it from his blog post here, and download it from his CodePlex project here. Steve Trefethen last week posted a VS starter kit for Facebook.NET which makes it even easier to get started. ASP.NET AJAX Silverlight -
Halo 3 Game Guide: Halo 3 ships this week, and no doubt many people will find themselves afflicted with a sudden illness that requires them to stay home one day this week. To help get you ready, watch one of the High Definition Halo3 Videos here (for a lower resolution video click here), and browse the Halo3 Game Guide here. Both are built with Silverlight 1.0. WPF and Expression Blend Hope this helps, Scott 
|
-
Consider the following diagram to track the votes in a contest. Each voter can register only one vote (a score from 1 to 4) for each contest entry.
For any given voter, you'll want to present a screen showing every entry in the competition, along with the score assigned to the entry by the voter (if a score exists). To fetch the data with SQL, I'd write something like:
SELECT E.EntryID, E.EntryName, E.EntryDescription, @VoterID AS VoterID,
(SELECT V.Score
FROM Votes AS V
WHERE (V.VoterID = @VoterID) AND (V.EntryID = E.EntryID)) AS Score
FROM Entries AS E
The query should yield a resultset like the following:
...
EntryID EntryName VoterID Score
13 EntryA 1 4
14 EntryB 1 2
15 EntryC 1 NULL
...
I thought the query would be difficult to express in LINQ, but I stumbled into a solution just by keeping a "SQL" mindset:
var q = from e in Entries
select new
{
EntryID = e.EntryID,
EntryName = e.EntryName,
EntryDescription = e.EntryDescription,
VoterID = voterID,
Score = (int?)(from v in e.Votes
where v.VoterID == voterID
select v.Score).FirstOrDefault()
};
The LINQ generated SQL looks amazingly similar to the hand generated SQL, which is a comforting sight!

|
-
My Toolbox column in the October 2007 issue of MSDN Magazine is avaiable online. The October issue examines three products:
- DatabaseSpy - a rich database and query management tool that works with a wide variety of databases.
- FileZilla - a feature-rich, open-source FTP client. Developers often need to FTP files to or from servers, and FileZilla is a free and powerful tool. The FileZilla project also includes an open-source FTP server implementation.
- NCache - a framework for creating and managing a cache store distributed over multiple computers.
This month's issue did not include a book review.
As always, if you have any suggestions for products or books to review for the Toolbox column, please send them into toolsmm@microsoft.com.
|
-
One of the questions I get asked fairly regularly is: "how can I can easily change different configuration settings in my web.config file based on whether my application is in a dev, qa, staging or production mode?" The most common scenario for this is one where an application uses different database connection-strings for testing and production purposes. It turns out you can easily automate this configuration process within the Visual Studio build environment (and do so in a way that works both within the IDE, as well as with command-line/automated builds). Below are the high-level steps you take to do this. They work with both VS 2005 and VS 2008. - Use ASP.NET Web Application Projects (which have MSBuild based project files)
- Open the VS Configuration Manager and create new "Dev", "QA", "Staging" build configurations for your project and solution
- Add new "web.config.dev", "web.config.qa", and "web.config.staging" files in your project and customize them to contain the app's mode specific configuration settings
- Add a new "pre-build event" command to your project file that can automatically copy over the web.config file in your project with the appropriate mode specific version each time you build the project (for example: if your solution was in the "Dev" configuration, it would copy the web.config.dev settings to the main web.config file).
Once you follow these steps, you can then just pick the mode your solution is in using the configuration drop-down in the VS standard toolbar: The next time you build/run after changing the configuration mode, VS will automatically modify your application's web.config file to pick up and use the web.config settings specific to that build configuration (so if you select QA it will use the QA settings, if you select Deploy it will use the Deploy settings). The benefit with this approach is that it works well in a source control environment (everyone can sync and build locally without having to make any manual changes on their local machines). It also works on a build server - including with scenarios where you are doing automated command-line solution builds. To learn more about the exact steps to set this up, please read the Managing Multiple Configuration File Environments with Pre-Build Events post that Scott Hanselman published earlier tonight. Also check out my ASP.NET Tips, Tricks, and Gotchas page for other ASP.NET Tips/Tricks recommendations. Hope this helps, Scott 
|
-
My good friend Jayme Davis just launched the beta version of Meiraware Business, an online invoicing application. I have been testing it for him over the last couple of months and I am pretty impressed. I am currently working on getting Paychex to take over my payroll, when that is complete I won't need Quickbooks anymore and I can start using this application for invoicing and payments.
Check it out. It's completely free during beta testing (Jayme has assured me there will be a free version after beta testing too)
-James

|
-
One of the subtle (but cool) new language features in the VS 2008 version of C# is the ?? "null coalescing" operator. This provides a nice, terse way to check whether a value is null, and if so return an alternate value. Simple Example Usages Several folks have blogged about the ?? operator in the past - read here, here, here, and here for some previous examples on how to use it. Simply put, the ?? operator checks whether the value provided on the left side of the expression is null, and if so it returns an alternate value indicated by the right side of the expression. If the value provided on the left side of the expression isn't null, then it returns the original value. For example, let's assume we have a string variable "message". We could check whether message was null, and return an alternate value using the code below: Because the "message" variable above wasn't null, the "result" variable is assigned the original "hello world" message value. In the code snippet below, however, message is a null value, and so the ?? operator will return the alternate value we've provided: The ?? operator works for both reference types and value types. For example, below we are checking whether the nullable integer "number" variable is null. Because it isn't, the result will be the original value (55): If "number" is null, then result is assigned the value 0: Using the ?? operator with LINQ Last month I wrote a blog post that covered using the new LINQ to XML support in .NET 3.5. One of the "gotchas" you often need to deal with when handling raw XML are cases where XML shapes are irregular and/or missing elements/attributes. The ?? operator can be very useful in these scenarios. For example, let's consider a scenario where we have an XML file or feed with the following contact data: We could write the below LINQ to XML code in C# to open the XML file and retrieve back a sequence of anonymous type objects with "Name", "Title", "Email" and "YearsAtCompany" properties, and then databind the results to an <asp:gridview> control on a page: Notice above how I'm using the explicit conversion operator support on the XElement class to retrieve strongly typed values from the XML. This enables me to just cast the c.Element("YearsAtCompany") value to an int - and it will then automatically convert the string value to an integer for me, and type the "YearsAtCompany" property on my anonymous type to be an int. When we run the above code snippet, we'll then get a nice Gridview listing of our contacts: This explicit conversion support works great when the <YearsAtCompany> element is always defined. But it will throw a runtime error in the case where we have a <Contact> that is missing a <YearsAtCompany> sub-element: One way to fix this is to modify our LINQ to XML query so that we indicate that YearsAtCompany is a nullable integer. We can do this by changing the explicit cast to be (int?) instead of (int): This enables our query to execute cleanly and not raise any errors. Instead a null value will be assigned to the YearsAtCompany property if no <YearsAtCompany> element is present in the XML. When we run the application and databind the results to the Gridview, you can see the YearsAtCompany column for our third contact is empty as a result (since the value is null): But what if we didn't want a missing XML value to result in a null integer value - but instead just indicate a value of 0? Well.... that is where we can use the new ?? operator support. We can just modify the LINQ to XML query like below to indicate a default value of 0 if no element is present: This indicates that if the <YearsAtCompany> element is missing in the XML, and the result would otherwise be null, instead assign a value of 0. Notice in the intellisense above how C# automatically detects that this means that the YearsAtCompany property on the new anonymous type will never be null - and so it marks the property to be of type (int) instead of (int?). And now when we run the page we'll see a value of 0 show up in our third row instead of a blank value: Summary You can use the new C# ?? operator in all types of scenarios. Hopefully the LINQ to XML scenario above provides some interesting food for thought on how you can use it with any LINQ scenario (including LINQ to SQL, LINQ to XML, LINQ to Objects, LINQ to SharePoint, etc). I think you'll find it cool and pretty useful. Hope this helps, Scott 
|
-
One of the features that VS 2005 added was support for HTML source validation. This enabled you to validate your page markup against different HTML schemas and standards (XHTML Transitional/Strict, HTML 4.01, various browser types, etc). You could also use the HTML validation features to detect missing link, image or style references in your markup. For example, if you have an HTML hyperlink in your page that points to a local file that doesn't exist, or if your markup uses (or misuses) HTML or CSS content, you'll by default see red squiggles in the source editor: And if the html document is open you'll by default see these issues listed in the error list: Note: if you don't want HTML validation support at all you can optionally turn off the html validation feature. Treating HTML, CSS and JScript Validation Issues as Warnings Instead of Errors One of the common requests with VS 2005 has been to not have these html markup issues added to the error list, but instead have them listed in the warnings list (which you can toggle to hide/show). This way you can have your error list only contain VB/C# code-related issues, and not be cluttered with a lot of markup problems. Mikhail Arkhipov from the Visual Studio Web Tools team recently posted about how support for this was just checked-in to a post Beta2 build of VS 2008. Specifically, you can now bring up the Tools-Options dialog and configure HTML, CSS and JavaScript issues to be treated as warnings instead of errors (I believe this is also now the default out of the box): This should make it easier (and cleaner) when working on large markup files. Hope this helps, Scott 
|
-
I still have plans to post about my two year project that wrapped up this summer, I keep starting a post and then trashing it. There was so much going on it's hard to know where to start. I will do it eventually, especially after being inspired by some great posts from Michael Eaton.
Michael Eaton has done a great job writing about the nightmare project he was on (actually with the same company as mine). Check out Part 1, Part 2, Part 3, Part 4, Part 5, and a bonus follow up.
-James

|
-
Here is the latest in my link-listing series. Also check out my ASP.NET Tips, Tricks and Tutorials page for links to popular articles I've done myself in the past. ASP.NET - Debugging Script: Dumping out Current and Recent ASP.NET Requests: Tess Ferrandez from the ASP.NET support team has an excellent post that details how to use the windbg debugger to dump out real-time information about what requests ASP.NET is currently processing on the server (super useful when investigating failures). She has a great script you can just run "as-is" in this article, as well as an in-depth discussion about how it works.
- Freezing GridView Column Headers with CSS and a Control Adapter: Matt Berseth has a cool article on how you can use CSS to implement a "frozen columns headers" feature with the standard <asp:gridview> control. Note that this type of scenario is much easier with the new <asp:listview> control in .NET 3.5, which enables you to customize all of the html markup emitted.
ASP.NET AJAX - Update for the iPhone: Matt Gibbs blogs about a fix you can apply to ASP.NET AJAX to address a change in the iPhone 1.01 patch that impacts how regular expressions are parsed in the iPhone Safari browser. Matt's fix enables you to continue targeting iPhone users with your ASP.NET AJAX applications.
Visual Studio - XML to Schema Inference Wizard for Visual Studio 2008: Scott Hanselman has a great blog post about a new item template wizard that makes it really easy to automatically infer an XML schema from a XML file or XML snippet. He then shows how you can use the cool new LINQ to XML features in VB9 to get automatic LINQ to XML intellisense inside VS 2008 with it.
IIS 7.0 Silverlight - Ink Recognition and Silverlight: Loren has a really cool sample built with Silverlight that demonstrates how you can use the ink pen recognition support within Silverlight to enable tablet or mouse based Google searches using a Silverlight application. A very cool mashup.
- Silverlight Spy Tool: Silverlight Spy is a small WinForms application capable of inspecting Silverlight 1.0 applications. You can use it to navigate a XAML object explorer of a running Silverlight application, trace out messages from it, and enable easier debugging of it.
- HtmlTextBlock control for Silverlight: David Anson has published a really cool control for Silverlight 1.1 that provides an easy way to take HTML input and display it using the text/graphics stack within Silverlight.
- Silverlight Dev Camp Chicago: Kevin Marshall is organizing an upcoming Silverlight DevCamp event in Chicago on September 28th-29th. You can attend completely for free.
Hope this helps, Scott 
|
-
The last two days I've been speaking at the the MIX:UK conference that was held this week in London. We had a sold out crowd of 500 people come to learn more about some of the new Microsoft web technologies. I gave 5 talks at the conference, including the Keynote and 4 breakout talks: Building Silverlight Applications with .NET (Part 1 and 2), and Building ASP.NET 3.5 Applications with VS 2008 (Part 1 and 2). I also had the chance to participate on 2 panels (including a really fun one where we sat around and drank tea, ate biscuits, and discussed technology trends). Below are the slides + demos from my talks if you are interested in downloading them. Building Silverlight Applications with .NET (Part 1 and 2) This two part session drilled into how to build Silverlight 1.1 applications using .NET. I really like the slide + sample approach of this talk (I first gave it at MIX:Hungary in June), and think it provides a really good way to learn the programming concepts of Silverlight 1.1 using .NET. Note: All samples are built using the current Silverlight 1.1 Alpha and VS 2008 Beta2 with the Silverlight Tools Alpha Installed. Building ASP.NET Applications using VS 2008 and .NET 3.5 (Part 1 and 2) This two part session was primarily a demo driven talk that shows off many of the new improvements for ASP.NET with .NET 3.5 and VS 2008. - Click here to download the slides from the talk.
- Click here to download the samples from the talk (these require VS 2008 Beta2).
To learn more about VS 2008 and .NET 3.5 Beta2 for web development, please also check out these recent blog articles of mine that cover some of its features in more detail: General: VS 2008: ASP.NET in .NET 3.5: LINQ to SQL: New Language Features: One last note... I usually get at least 4-5 emails a week from people asking whether they can re-use some of my slides/samples for their own presentations (or books). My answer to this is always "absolutely!" Please do not worry about asking for permission on this - you can always re-use any of the content from my talks and blog postings (and feel free to re-use slides and decks wholesale). I write this content to help people learn how to use .NET - so you helping spread the information is pure goodness from my perspective (my blog is technically not part of my official job, rather just a side hobby I enjoy and find useful). Hope this helps, Scott 
|
-
My Toolbox column in the September 2007 issue of MSDN Magazine is avaiable online. The September issue examines three products:
- ASPxperience Suite - a suite of 18 ASP.NET server controls designed to enhance your web application's aesthetics and usability by presenting information in interesting and attractive ways.
- FTP for .NET 2.0 - a comprehensive API for connecting, uploading, and downloading files to and from an FTP server.
- DotImage Photo Pro - a powerful and easy-to-use imaging API with a number of imaging controls for WinForms and Web Forms.
This month's issue reviewed Pro SQL Server 2005 Database Design and Optimization, by Louis Davidson, Kevin Kline, and Kurt Windisch. Here is an excerpt from the review:
The scalability, extensibility, and maintainability of a database are directly related to the quality of its design. As such, it is important that the developers creating the data model for a data-driven application have a solid understanding of the principles of good design. Pro SQL Server 2005 Database Design and Optimization, by Louis Davidson, Kevin Kline, and Kurt Windisch (Apress, 2006), introduces readers to these principles and illustrates how to implement them in SQL Server™ 2005.
As always, if you have any suggestions for products or books to review for the Toolbox column, please send them into toolsmm@microsoft.com.
|
-
As I blogged about earlier, I turned off comments this summer because I was going 'off the grid' for much of the summer and didn't want comment spam to accumulate. We're back from our summer of travel, so comments have been re-enabled. The quantity of blog posts here will also pick up as I get back into the swing of things.
|
-
Most server-side applications run on machines under our control. We know what the application's environment will look like long before deployment.
Building and packaging an ASP.NET application to deploy inside of any corporate firewall is a bit more challenging. Here are a few lessons I've learned from five years of building a commercial web app.
- Document your required configuration. Use this document in the sales cycle and again before delivering the software to make sure there are no surprises.
- Verify the environment. Even though your document says you require SQL 2005 SP2, someone will point your software to a server with SQL Server 7.0. Small mistakes like this can eat up a surprising amount of time. Write some software that will verify versions, service packs, CPU, memory, and other environmental requirements.
- Two words: least privilege. In today's world, someone will challenge you over all privileges you request. You need to be in the db_creator role? Why? You need to do what on our Active Directory? Why? It's best to clearly document these required privileges and explain how you use them.
- Look at the licensing of third party components before looking at the feature list. As soon as you find the perfect grid control, you'll find it's too expensive to deploy. Many of the commercial controls and components you can buy for server-side software are geared less towards redistribution and more towards "per server" or "per CPU" licensing.
- Be creative about getting diagnostics. Log errors to help debug problems, but don't count on using the event log as it may not be well maintained. The file system is generally more reliable, and many logging components offer rolling log file options. To be proactive, consider sending diagnostic information directly back to your company – just don't use email. In my experience, sending email from a web server inside the firewall out over the Internet is only going to work about 30% of the time – corporate IT departments are just too leery. Consider hosting a web service at your place that the web app can contact over port 80, but be prepared to use a proxy server.
- Create and install a database maintenance plan. No one else will.
- Ruthlessly automate the installation. Every manual step in the installation is a problem waiting to happen.
- Be wary of virus scanners. Many corporate departments require them, but unfortunately, they can do some funky stuff to an ASP.NET application - frequent restarts and lock assemblies. Try to impress on the new owners of your application that they can exclude your directories from scanning.
- Be wary of impersonation. Let's say you need access to a network resource, so you place the encrypted username and password of a domain account into web.config. At runtime, you use the credentials to impersonate a domain account and reach the resource. This strategy will work well for about three months, then that corporate password change policy is enforced, and your application starts throwing mysterious errors.
- Stay out of the default AppPool in IIS6. Because you don't know who your neighbors are going to be. They might like to stay up late, use too much memory, play loud music, and run with a different version of the CLR.

|
-
Over the last few weeks I've been writing a series of blog posts that cover LINQ to SQL. LINQ to SQL is a built-in O/RM (object relational mapper) that ships in the .NET Framework 3.5 release, and which enables you to model relational databases using .NET classes. You can use LINQ expressions to query the database with them, as well as update/insert/delete data. Below are the first eight parts in this series: In Part 5 of the series I introduced the new <asp:LinqDataSource> control in .NET 3.5 and talked about how you can use it to easily bind ASP.NET UI controls to LINQ to SQL data models. I also demonstrated how to use it a little more in a follow-up post I did that discusses the new <asp:ListView> control (Part 1 - Building a Product Listing Page with Clean CSS UI). In both of these articles the queries I performed were relatively straight-forward (the where clause worked against a single table of data). In today's blog post I'll demonstrate how to use the full query expressiveness of LINQ with the LinqDataSource control, and show how you can use any LINQ to SQL query expression with it. Quick Recap: <asp:LinqDataSource> with a Declarative Where Statement In these two posts I demonstrated how you can use the built-in filter capabilities of the LinqDataSource control to declaratively express a filter statement on a LINQ to SQL data model. For example, assuming we had created a LINQ to SQL data model for the Northwind database (which I covered how to-do in Part 2 of this series), we could declare a <asp:LinqDataSource> control on the page with a declarative <where> filter that returns back only those products in a specific category (specified via a querystring "categoryid" value): We could then point a <asp:gridview> control at the datasource and enable paging, editing, and sorting on it: When we run the above page we'll then have a GridView with automatic sorting, paging, and editing support against our Product data model: Using declarative <where> parameters like above works well for many common scenarios. But what happens if you want the Product filtering to be richer or more complex? For example, what if we only wanted to display products made by suppliers based in a dynamic set of countries? Using the <asp:LinqDataSource> Selecting Event To handle custom query scenarios you can implement an event handler to handle the "Selecting" event on the <asp:LinqDataSource> control. Within this event handler you can write whatever code you want to retrieve a data model result. You could do this with a LINQ to SQL query expression, or call a Stored Procedure or use a Custom SQL Expression to retrieve the LINQ to SQL data model. Once you retrieve a sequence of data, all you need to-do is to assign it to the "Result" property on the LinqDataSourceSelectEventArgs object. The <asp:LinqDataSource> will then use this sequence as its data to work with. For example, below is a LINQ to SQL query expression that retrieves only products from suppliers based in a specific set of countries: VB: C#: Note: you do not need to write your query expression in-line within the event handler. A cleaner approach would be to encapsulate it within a helper method that you just call from the event handler. I show how to create one of these helper methods in the beginning of my Part 8 blog post (using a GetProductsByCategory helper method). Now when we run our page using the custom Selecting event handler, we'll only see those products whose suppliers are located in our array of countries: One of the really cool things to notice above is that paging and sorting still work with our GridView - even though we are using a custom Selecting event to retrieve the data. This paging and sorting logic happens in the database - which means we are only pulling back the 10 products from the database that we need to display for the current page index in the GridView (making it super efficient). You might ask yourself - how is it possible that we get efficient paging and sorting support even when using a custom selecting event? The reason is because LINQ uses a deferred execution model - which means that the query doesn't actually execute until you try and iterate over the results. One of the benefits of this deferred execution model is that it enables you to nicely compose queries out of other queries, and effectively "add-on" behavior to them. You can learn more about this in my LINQ to SQL Part 3 blog post. In our "Selecting" event handler above we are declaring a custom LINQ query we want to execute and are then assigning it to the "e.Result" property. We haven't actually executed it yet though (since we didn't try and iterate through the results or call ToArray() or ToList() on it). The LINQDataSource is therefore able to automatically append on a Skip() and Take() operator to the query, as well as apply an "orderby" expression to it -- all of these values being automatically calculated from the page index and sort preference of the GridView. Only then does the LINQDataSource execute the LINQ expression and retrieve the data. LINQ to SQL then takes care of making sure that the sort and page logic is handled in the database - and that only the 10 product rows required are returned from it. Notice below how we can also still use the GridView to edit and delete data, even when using a custom LinqDataSource "Selecting" event: This editing/deleting support will work as long as our Selecting event assigns a Result query whose result sequence is of regular entity objects (for example: a sequence of type Product, Supplier, Category, Order, etc). The LINQDataSource can then automatically handle cases where UI controls perform updates against them. To learn more about how updates work with LINQ to SQL, please read Part 4 of this series. Then read Part 5 of the series to see Updates in action with the LinqDataSource. Performing Custom Query Projections with the Selecting Event One of the powerful features of LINQ is its ability to custom "shape" or "project" data. You can do this in a LINQ to SQL expression to indicate that you want to retrieve only a subset of values from an entity, and/or to dynamically compute new values on the fly using custom expressions that you define. You can learn more about how these LINQ query projection/shaping capabilities in Part 3 of this series. For example, we could modify our "Selecting" event handler to populate a GridView to display a custom set of Product information. In this Grid we'll want to display the ProductID, Product Name, Product UnitPrice, the Number of Orders made for this Product, and the total Revenue collected from orders placed for the Product. We can dynamically compute these last two values using a LINQ expression like below: VB: C#: Note: The Sum method used in the Revenue statement above is an example of an Extension Method. The function it takes is an example of a Lambda expression. The resulting type created by the LINQ query expression is an anonymous type - since its shape is inferred from the query expression. Extension Methods, Lambda Expressions, and Anonymous Types are all new language features of VB and C# in VS 2008. The result of our custom LINQ expression when bound to the GridView will be UI like below: Note that paging and sorting still work above with our GridView - even though we are using a custom LINQ shape/projection for the data. One feature that will not work with custom shapes/projections, though, is inline editing support. This is because we are doing a custom projection in our Selecting event, and so the LinqDataSource has no way to safely know how to update an underlying entity object. If we want to add editing support to the GridView with a custom shaped type, we'd want to either move to using an ObjectDataSource control (where we could supply a custom Update method method to handle the updates), or have the user navigate to a new page when performing updates - and display a DetailsView or FormView control that was bound to a Product entity for editing (and not try and do inline editing with the grid). Summary You can easily perform common query operations against a LINQ to SQL data model using the built-in declarative filtering support of the LinqDataSource. To enable more advanced or custom filtering expressions, you can take advantage of the LINQDataSource's Selecting event. This will enable you to perform any logic you want to retrieve and filter LINQ to SQL data. You can call methods to retrieve this data, use LINQ Query Expressions, call a Stored Procedures, or invoke a Custom SQL Expression to-do this. Hope this helps, Scott 
|
-
I'll blog again as soon as this little operation finishes....

|
-
I am going to be pinch hitting for Scott Mitchell on a couple Toolbox columns for MSDN Magazine and while I have plenty of my own favorite tools and books I want to write about, I wanted to get some reader input as well. What tool have you recently starting using that you love (I mean really love)? What book have you recently finished that you would recommend I read?
-James

|
-
I will probably be lost in most of the sessions I attend, but when it's in Charlotte (only a couple hours away) it's too good of an opportunity to pass up. It's only $250 and they got a sweet deal on the rooms at a nice hotel, so it's a small price to pay considering the agenda.
Anyone else going?
-James

|
-
Silverlight is a cross platform, cross browser plug-in that enables designers and developers to build rich media experiences and .NET based RIAs for the web. I first blogged about Silverlight back in May after we announced it at our MIX conference in Las Vegas. Silverlight 1.0 and Expression Encoder 1.0 Released Today we shipped the Silverlight 1.0 release for Mac and Windows on the web. Silverlight 1.0 is focused on enabling rich media scenarios in a browser. Some of its features include: - Built-in codec support for playing VC-1 and WMV video, and MP3 and WMA audio within a browser. The VC-1 codec is a big step forward for incorporating media within a web experience - since it supports very efficiently playing high-quality, high definition video in the browser. It is a standards-based media format that is implemented in all HD-DVD and Blueray DVD players, and is supported by hundreds of millions of mobile devices, XBOX 360s, PlayStation 3s, and Windows Media Centers (enabling you to encode content once and run it on all of these devices + Silverlight unmodified). It enables you to use a huge library of existing video content and provides access to the broad ecosystem of existing Windows Media tools, components, vendors and hardware.
- Silverlight supports the ability to progressively download and play media content from any web-server. You can point Silverlight at any URL containing video/audio media content, and it will download it and enable you to play it within the browser. No special server software is required, and Silverlight can work with any web-server (including Apache on Linux). We'll also be releasing an IIS 7.0 media pack that enables rich bandwidth throttling features that you can enable on your web-server for free.
-
Silverlight also optionally supports built-in media streaming. This enables you to use a streaming server like Windows Media Server on the backend to efficiently stream video/audio (note: Windows Media Server is a free product that runs on Windows Server). Streaming brings some significant benefits in that: 1) it can improve the end-user's experience when they seek around in a large video stream, and 2) it can dramatically lower your bandwidth costs. -
Silverlight enables you to create rich UI and animations, and blend vector graphics with HTML to create compelling content experiences. It supports a Javascript programming model to develop these. One benefit of this is that it makes it really easy to integrate these experiences within AJAX web-pages (since you can write Javascript code to update both the HTML and XAML elements together). -
Silverlight makes it easy to build rich video player interactive experiences. You can blend together its media capabilities with the vector graphic support to create any type of media playing experience you want. Silverlight includes the ability to "go full screen" to create a completely immersive experience, as well as to overlay menus/content/controls/text directly on top of running video content (allowing you to enable DVD like experiences). Silverlight also provides the ability to resize running video on the fly without requiring the video stream to be stopped or restarted. Today we also shipped the Expression Encoder 1.0 release on the web. Expression Encoder is part of the Microsoft Expression suite of products, and enables designers and content professionals to enhance, encode and publish media content for Silverlight. You can use it to import media files from a variety of formats (QuickTime, WMV, AVI and more), add leaders and trailers to videos for advertising or roll credits, easily watermark video with corporate logos or brands, and then tune the encoding settings to create optimal web-friendly Silverlight experiences. Deployed Silverlight 1.0 Customers This week we'll have a wide range of customers already deployed live on the Silverlight 1.0 release. A few of them include: MLB.com (Major League Baseball), Home Shopping Network, World Wrestling Entertainment, and the "Entertainment Tonight" show. Silverlight is also now deployed on several Microsoft sites, including the Halo 3 preview site (click here for the awesome HD version), Tafiti.com, MSN Extra, and MSN Podium '08. You'll also see Silverlight used prominently in several upcoming MSN and Microsoft.com sites. Silverlight for Linux Support Over the last few months we've been working to enable Silverlight support on Linux, and today we are announcing a formal partnership with Novell to provide a great Silverlight implementation for Linux. Microsoft will be delivering Silverlight Media Codecs for Linux, and Novell will be building a 100% compatible Silverlight runtime implementation called "Moonlight". Moonlight will run on all Linux distributions, and support FireFox, Konqueror, and Opera browsers. Moonlight will support both the JavaScript programming model available in Silverlight 1.0, as well as the full .NET programming model we will enable in Silverlight 1.1. Below is a screen-shot of the Silverlight 1.1 Flight-Picker application I built in my keynote at MIX running on Linux using Moonlight: Keep an eye on Miguel de Icaza's blog - I know he'll be blogging a lot more about our partnership on this shortly. Silverlight 1.1 Update Now that Silverlight 1.0 is out the door, my team is cranking hard on our Silverlight 1.1 release. Silverlight 1.1 will include a cross-platform version of the .NET Framework, and will enable a rich .NET development experience in the browser. It will support a WPF programming model for UI - including support for an extensible control model, layout management, data-binding, control skinning, and a rich set of built-in controls. It will also include a subset of the full .NET Framework base class library you use today, including support for collections, generics, IO, threading, globalization, networking (including sockets, web-services and REST support), HTML DOM, XML, local storage, and LINQ. You'll be able to use any .NET language to develop a Silverlight application (VB, C#, JavaScript, Python, Ruby, Pascal, and more). It is going to really open up a lot of new development opportunities. How to Learn More about Silverlight Visit the www.silverlight.net community site to learn more about Silverlight and how to get started with it (and visit the Silverlight video page for free short videos on how to develop with it). You can use any text editor to build Silverlight applications. If you have VS 2008 or the free Visual Web Developer Express 2008 edition, you might want to download this library to get JavaScript intellisense for Silverlight 1.0. If you are building .NET applications using the Silverlight 1.1 Alpha, you can download the Silverlight Tools for VS 2008 Alpha and Expression Blend Preview. Hope this helps, Scott 
|
-
-
Ok, I have been trying to write something up here about the books I have been reading. But I am way too far behind, so I am going to get a bunch out of the way in one post. I have also decided that in the future I am not going to review books I don't like, I will just pretend like I never read them. I might make a post like this a running story like "Books of 2007" instead of posting them to the main feed... not sure yet.
"The Winds of War" (Herman Wouk) - This was an incredible book and I can't wait to start War and Remembrance. Its an amazing epic story set in the years before the United States joined World War II. The story centers around a naval officer who ends up in the middle of a plethora of historic events.
"The Second World War: A Complete History" (Martin Gilbert) - I have read a number of books about specific parts of WWII, but I have never read a good overall book about the war and had to put the specific books in context based on my public school education. This book was exactly what I was looking for. The book covers the war from beginning to end with a large focus on the innocent lives taken during the war and a slight british slant.
3 Augusten Burroughs books ("Running with Scissors: A Memoir", "Dry: A Memoir" , "Sellevision: A Novel" )- I enjoyed Running with Scissors when I read it, but after reading some of the doubts about its accuracy I have kind of soured on it a little bit. I know a memoir doesn't have to be pure fact, but its hard not to feel duped when presented with the idea that much of it could be false. The other two were readable but nothing special.
"Harry Potter and the Deathly Hallows (Book 7)" (J. K. Rowling) - Of course I read this one, who hasn't? It was excellent and I can't think of anyway she could have possibly ended the series in a better way.
"The Last True Story I'll Every Tell: An Accidental Soldier's Account of the War in Iraq" (John Crawford) - This book was a great account of a reservist's time in the war. It really gives you a feeling for what it must be like fighting over there and the end is heartbreaking.
"A Dirty Job: A Novel" (Christopher Moore) - This was a fun beach read for the summer. Very funny but gets a little lost at the end.
All caught up!
-James

|
-
For the first time in a long time I added a new category to the blog. The new category is "Ruby/Rails" and will be for any tips or tools I come across as I experiment with Ruby on Rails.
My little side project is coming along nicely, I hope to have something to put out there in beta in a couple weeks... maybe less. This is actually my second time learning Rails (the first time around I ended up getting distracted and put it down for almost a year). So much has changed that it is almost like re-learning everything. One of the problems I had last time around was that I didn't do a good job writing and running tests, I wanted to make sure I did a better job this time around.
Writing tests is simple, but I wanted to make sure I had good coverage. This led to me to rcov which does a good job of running my tests and showing me a nice HTML output of the coverage. It was still a pain to go and run rcov and hunt down the report (I am used to nice in the IDE integration like TestDriven.NET).
So I did some searching and ran across a nice rake plugin called rails_rcov that does it all for me. Now I can run rake test:test:rcov from TextMate and see all my tests run and view my coverage.
-James

|
|
|
|