Hit ‘em with the Force like Obi

Shortest possible code to get specific files in a directory

IEnumerable fileList = new DirectoryInfo(pathToFiles).GetFiles().Where(file => file.Extension == “.txt”);

I remember when this took more than one line…

April 7, 2009   No Comments

ASP.NET MVC 1.0 RTW!

Download here.

You have to change your thought process (which proves difficult after years of web forms) from URLs -> files on disk to URLs -> methods on classes. Honestly that’s MVC in its broadest sense. I think I have a good candidate to use MVC for, mainly for my benefit, since there have been changes since Preview 4-5, and its a situation where I think MVC is probably appropriate, incidentally, I’m going to port an application written on Rails to MVC…that is, if Kaden gives me enough time to.

March 24, 2009   No Comments

WCF Service Parameter Validation

I posted this over on stackoverflow, but it seems bizarre to me that when you use the Validation Application block from Enterprise Library with WCF service operations with parameter level validation, a caller will simply get a FaultException with the message, “the creator of this fault did not specify an exception”. In theory you could write a custom fault class, and check the parameters and throw the custom fault, but that sort of defeats the purpose of a ValidationFault FaultContract. Meh, maybe I am doing something wrong.

For example

[OperationContract(Name="GetFoo")]
[FaultContract(typeof(ValidationFault))]
string GetFoo([DomainValidator("Bar")] string input)

So this says the only valid value for the string input parameter is “Bar”, but yet if a caller calls GetFoo, it will return the “the creator of this fault did not specify an exception”. There must be some way to alter this. Inheriting from ValidationFault was useless, no virtual methods found.

January 16, 2009   No Comments

A note about the C# Wow Armory code

This post I made about parsing the wow armory xml is probably outdated. When I first wrote it the armory was fairly new and the url has since changed, if you are using the code or downloading it, you will probably have to adjust your code for the new URL and possibly change some of the xpath queries I used, I haven’t seen if Blizzard has changed the structure of the results from the armory lately. I’m only posting this because I see a lot of “C# Wow Armory” referrals coming in.

November 26, 2008   1 Comment

“Official” ASP.NET charting controls

from ScottGu

This was long over due. It probably helped that Microsoft purchased Dundas’ data visualization components last year.

November 26, 2008   No Comments

A couple things we did for doczu

With inspiration from Jeff Prosise, all data calls for doczu are asynchronous, as well as file uploads. Incidentally, we use AmazonS3 for the actual storage. The other part that is pretty cool is we are using DIME attachments to actually upload the content. S3 as of now, doesn’t support MTOM.

The exercise was not really to build anything ground breaking, but sort of to use all the available technologies today. Imagine if this was 7-8 years ago, and for kicks you wanted to build an application that stored documents, you’d end up having to find a host, buy enough room either in terms of storage space or database space and pray for uptime. Some people are still skeptical on the cloud, but without AmazonS3 I don’t know how trivial this would have been. The S3 API is mind numbingly simple, I just wrote wrapper classes in .NET, and ensured the content type of the document was something text/office doc based (you cant just change the extension and upload a .exe or .jpg), the trick was getting file uploads working asynchronously DIRECTLY to S3. I know S3 now offers direct POSTS , but when doczu was written (which took months because Daniel and I would work on it maybe 15-20 min a day after a long day at work after which we would play Battlefield2), there was no such feature. So the norm was to upload a file to your local file server and then send it to S3. I’m not saying doczu is revolutionary, but we were doing direct uploads without an interstitial step before doing it was “cool”. ;)

November 21, 2008   No Comments

The poor man’s hierarchical GridView, its like 2001 all over again…

I’ve seen questions asked on newsgroups and stackoverflow.com on how to create a hierarchical gridview in asp.net, and there really has never been a clear answer. I’m not sure if Microsoft will ever include this out of the box with asp.net but there is a quick and dirty to mimic this kind of behavior by using a gridview inside a gridview. You could probably use a Data List inside the templated column as well.

STANDARD DISCLAIMER: THIS was written in 15 minutes, and is by no means an example of how to write efficient code, it was written just to show how to build a simple hierarchical grid view with minimal effort

Getting authors data and binding it to a grid is pretty trivial, in fact I haven’t used direct ADO.NET calls in a long time, I am so used to using Subsonic or LINQ, it was funny to actually write code that opened a connection, used a DataAdapter and filled a dataset, its like 2001 all over again.
The code is included as a download, but here are a couple of key points:

•We will add a Gridview to a standard web form that loads the au_id’s from the author’s table from the pubs database
•These au_id’s will be represented in a single template column in a grid view. This single template column will also include a button with -> [+] as the text property. You can get all fancy and include image buttons (see STANDARD DISCLAIMER)
•Since we’re not using the standard Edit/Update/Cancel functionality we’re going to set the edit index of the grid programmatically, so when the [+] is clicked we know which row we are working with. To make this simple, we hook into the OnRowDataBound event and set the CommandArgument property of each button to the current row index
•When the expand button is clicked, we check its text (see STANDARD DISCLAIMER ), if it is a ‘[+]’ we know we need to load our nested gridview. The nested GridView is included in the EditItemTemplate as a control. So when we trick the grid to thinking it is in Edit mode programmatically, all we are doing is calling another method that passes in the au_id of the current row, and getting the titles associated with that author id. Its just that simple.

Below are screenshots and the code is attached.

Before

After

Edit: Source vs2008 — remember to change the connection string to pubs.

November 18, 2008   No Comments

I’m here!

Well, I’ve been gone a while, and I could write up the usual excuses, not that my 5 readers would care anyway, but Daniel and I worked on a document sharing site (written in ASP.NET/C# using SQL2k5) for a little bit. Its nothing too fancy, but it its using Scribd.com’s viewer. You can upload and share as many documents as you wish, you can even mark documents as private if you want to use it as some huge personal file share.

The only caveat is that the content type of your document must be text based, although most productivity application documents can be uploaded. It was a hobby project that turned into something we actually shipped. The total time spent writing the code was minimal, although it took a while because of our day jobs. All of the calls are asynchronous, not that anyone cares!

Ahh what else, oh yes the Gamecocks are 7-3 as of this writing and Kaden (my son) is almost 22 months old. How time flies.

I went to a Pluralsight training course in Boston earlier this year taught by Matt Milner and David Cowles which was really great. I recommend this course to anyone trying to get up to speed on WCF and WPF, although each of those areas could easily be a 5 day course.

November 11, 2008   No Comments

Getting VS2005 Team Explorer to Connect to TFS2008

As you can see from here there is a nasty error that pops up when you try to create a new team portal site from Visual Studio 2005 which is connecting to Team Foundation Server 2008.

If you look at the error log the problem is as follows:

Event Description: TF30162: Task “SharePointPortal” from Group “Portal” failed

Exception Type: Microsoft.TeamFoundation.Client.PcwException

Exception Message: The language id specified in the process template does not exist on the WSS server.

VS2005 will show you this:

“The language id specified in the process template does not exist on the WSS server”

On the weblog referenced above the hot fix indeed works, but most of the comments indicate it is not.

Here is the solution:

YOU must reinstall Visual Studio Service Pack SP1 before applying the Hotfix.

This problem happens because VS2005 SP1 was applied before installing the VS2005 Team Explorer Client.

So the version of the dll that is causing the problem is:

Microsoft.VisualStudio.TeamFoundation.TeamExplorer.dll -> 8.0.50727.147 - this version is not what is expected by the hotfix.

After you apply SP1, the version of this dll is correct, and the hotfix will work, and you will be able to connect to TFS2008 from a VS2005 Client.

Everything should work now.

July 17, 2008   No Comments

Getting Subsonic to work with NUnit

I just started using SubSonic after Matt used it recently on a project. Setting it up was pretty straightforward, but when I tried to write some test cases using Nunit and tested my class library using the nunit-gui, I kept getting the following error:

“Cant Find the SubsonicService in your application’s config.”

Now if I converted my test class library into a console app, and spit out the results of by subsonic based calls, everything worked just fine.
What I discovered was that if you create a config file with the same name as your Nunit project file and add the subsonic section, everything will work. (Not to be confused with YourClassLibrary.dll.config).

So if your Nunit project is called Leet.nunit you need to create a config file called Leet.config and include the SubSonic configuration sections and then the nunit gui will happily test any code written with subsonic

November 23, 2007   4 Comments