Input type=file value

I had a bug this morning where the input field for a file upload box was being cleared during a postback to the server. The bug suggested that the server action should not clear the field because we weren't uploading the file yet. In ASP.NET you cannot change the value of that field.

After thinking about this for a while, it makes sense. The vulnerability would be that some rogue web page would set the value to something private like your Quicken datafile and you'd unknowingly upload that to the server.

It is good that I as a programmer cannot set a value to this field, but am I looking at this correctly? Can anyone out there confirm that this is the expected behavior of <input type="file"> ?

How to take down a web site temporarily

Usually I rename web.config to web.config.bak while I make major changes to a web site. This causes an error page to anyone hoping to visit the site that I am modifying. In ASP.NET 2.0 you can take your web site offline and redirect traffic to a page that you can control its content (i.e. not an ASP.NET error page) simply by adding a web page called App_Offline.htm.

Thanks to Erik Porter's Blog for pointing this out.

MCMS Links

It's time for me to get ramped up on MCMS again as a big client wants their site written using that tool. I always get asked pretty much the same questions so I'm going to try to centralize all of the links to the answers. For the most part, the Microsoft public newsgroup is an amazing resource. Stefan Gossner from Microsoft answers so many questions, so fast, that I'm amazed that MVP's even exist for MCMS. I recommend his book and he has a new book coming out soon.

Anyway,

Question 1) How do I revert to a previous version of a post?

Answer 1) http://www.gotdotnet.com/Community/UserSamples/Details.aspx?SampleGuid=5801E02F-AF3A-413F-8985-A773336D84D8

HTML Validation: Choosing a DOCTYPE

A while back, I asked the question of what the XHTML 1.1 doctype is. The answer is found on the W3.org site here. It is this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

They suggest that the xmlns and xml:lang attributes be set for the html tag like this:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

Also, if you are up to it, add the xml declaration to it (<?xml version="1.0" encoding="UTF-8"?> at the top).

I am interested in this because I've been working on redesigning my main web site to make it more colorful, easier to update, and more modern in the code. When it's finished I'll be sure to post everywhere to let you know.

Vista {hearts} RSS... but hates developers

The RSS platform in Vista has three parts:

  • Common Feed List
  • Common Data Store
  • Platform Sync Engine

The data itself is structured like a directory structure. At the top is Feeds (a collection of feeds). Within Feeds there are a list of one or more folders. Each folder can contain zero or more folders and zero or more Feed. Each folder also has a folder properties.... er... properties. Each Feed has one or more Item and Feed Properties. Each item has zero or more enclosures and item properties. Each enclosure has enclosure properties.

Looks like when a sync is performed the system will create a folder structure containing any enclosures held within the feed. That means that audio-feeds (podcasts) and video-feeds will be automatically downloaded and placed into a virtual folder. This is a very good thing for managing synchronization of these items to various devices.

The sync engine will perform most of the really boring aspects of getting RSS feeds. Namely inserting new items, updating existing items, and ignoring the hell out of old crap. Can you tell how much I enjoy doing that part of it today?

Everything up to this point sounds great, and it reads great on this page. Now this is where I get lost. I'm excited about it. This weekend (Labor Day weekend here in the US) I've decided that I will only run Windows Vista on my main machine. I will immerse myself in trying out all the cool things in Vista. Specifically I am looking at trying out the Auxiliary Display Platform, the MMC 3.0, and of course RSS. I installed the PSDK, and I have my trusty Beta 2 of VS 2005 all hot and ready for action. This is where the problem occurs. What is the name space for all of this cool RSS functionality? Where are they hiding it? It isn't listed in the PSDK, and I can't find any code samples anywhere on the web. Did they take it out at the last minute?

.NET Maximum Request Length Exceeded

On a day to day basis I develop in Microsoft Content Management Server (MCMS 2002 SP1a). For most of what I've done editing the Metabase.xml file takes care of the problems I've had in uploading large files. Until today. A co-worker was entering content into a site that we are currently working on and he came across the "System.Web.HttpException:Maximum request length exceeded." error. After a brief look to ensure that I had made the changes to the metabase I was reminded that there is also a machine.config file. Inside the machine.config file you need to set the maximum request to a value larger than 4096 (4MB). In our case we had a zip file that was ~140MB that we needed to add to resource manager. Open the machine.config (usually found in "C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\CONFIG" but your setup may be different than mine) and look for the tag "<httpRuntime". Within this tag just change the "maxRequestLength" to something large enough to handle your files.

1, 0, 0 in x seconds

I am fascinated with test driven development/design (TDD). I am reading everything I can get my hands on about the topic. I highly recommend a Microsoft Press book written by Ron Jeffries titled "Extreme Programming Adventures in C#". TDD speaks to me as a developer in so many ways that I cannot even begin to explain. If I write a line of code, how do I know that line of code works? More importantly than that question is the greatest question a person can ask: "Why?" More specifically, "Why did I write that line of code?"

Mike Roberts has a blog entry titled, "Popping the Why Stack" where he took the idea of why in a different direction, but I think we end up in the same place. The last element in the TDD-Why stack should be: "Because it fills a specific need in this customer story." That means that the ultimate answer to the question, "Why did I write that line of code?" should always be, "because it solves this problem for the customer." How, then, do I get from a list of customer stories or requirements, to a single line of code? TDD has the answer to this, and it all has to do with being as lazy of a programmer as possible.

Being lazy is harder than it looks. It means that you should write the smallest amount of code that will solve a problem and not a single line more. TDD (and common sense) tells us that before I can solve a problem, I have to have a problem to solve. The problem that I need to solve is defined simply in a test, and let me tell you when that test fails it is a red light piercing my brain telling me I'm a screw up, a loser, nobody likes me, and my fellow programmers are all laughing at me. (Please note that I consider getting the system to compile without errors or warnings to be an implicit test.) So quickly I go and write the smallest amount of code required to get that test to pass. I say quickly because if I'm fast enough, none of you will notice that I had a failing test. Once the test is green, I can go and clean up my code (A.K.A. refactor), and write another test to start this whole cycle again.

Today, I had the opportunity to listen to a Microsoft MVP present an Education Day on an introduction to test driven development. It started at 8:30AM and was supposed to last until 5PM. I left at 2PM because I just couldn't take it anymore. Maybe I'm wrong, but the step where you clean up your code, also known as refactoring, should not make any changes to the way your code operates, and should not introduce any new complexity. The reason for that is that there is no reason to change your code. What I mean is that all of the tests pass at this stage. You've solved all of the problems that need solving. If I have a section of code that loops through all the elements in an array, and that section of code is in two or more methods, then yeah, refactor that bad boy and move on. But if I only have one test and it is looking to see if 5 is returned from some method, I'm not going to change that method from "return 5;" to "return myFavoriteProperty;" unless I have some test that is failing.

This is where the presenter was driving me nuts. He would change it from "return 5;" to "return myFavoriteProperty;" and he was doing it under the guise of "code clean up". He should have waited until he had a test that failed. He was trying to solve a problem before there was a problem to solve.

I understand that many of you that are reading this (I know there have been only 5 hits to this site since December, but I'm sure someone will come along soon) will tell me that he was just an experienced TDD'er and he was just thinking ahead. If that was the case I'd agree and let it go. However, you have to understand the audience. Half of the people had never heard of NUnit before. Also, you have to understand the topic he was selling (emphasis added), "an Introduction to test driven development." All this adds up to the fact that there are now about 75 programmers out there that think that the third step in TDD is to change your code to fit a future requirement that has no test calling for a solution.

That is the point I am trying to make with this entry. I hope that if I am wrong you will be kind and provide constructive feedback. After all, we only practice programming to find a better solution.