Lee Kelleher’s Weblog

Just another WordPress.com weblog

Archive for the ‘code’ tag

How to best embed a WMV video clip?

with 4 comments

I hate to admit it, but I’m stuck… I’m trying to figure out how to best embed a WMV video clip in a web-page, so that it works cross-browser (and cross-platform).

Even after all my years of web-development, I’m still confused to which browser supports which tag … nested <embed> tags in <object> tags … it gets messy!

I’m as equally confused with the Class ID attribute: “CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6” - surely that can’t be the same across all browsers/platforms?!

A List Apart article discusses dropping the <embed> tag. Which sounds like a good idea to me. The HTML looks so much better… MIME types all the way baby!!


<object type="video/x-ms-wmv" data="/media/video.wmv" width="320" height="260">
	<param name="src" value="/media/video.wmv" />
	<param name="autostart" value="0" />
	<param name="controller" value="1" />
</object>

I tested this on Firefox 2.0 and IE7 on Vista, and IE6 and Safari on XP - all fine, so far so good! When I ask my client to test the page on their Mac … it’s no good! The videos just wouldn’t load! Hmphf!

So does anyone know of a simple way of embedding a WMV video clip that works cross-browser/platform? Please let me know, I’d be very a happy developer!

Otherwise, I’m so close to using the beastly code that comes from the “Embedded Media HTML Generator” … help me please! ;-)

Written by Lee Kelleher

June 9th, 2008 at 2:56 pm

Posted in blog

Tagged with , , , , , ,

How to convert NameValueCollection to a (Query) String

with 5 comments

Most ASP.NET developers know that you can get a key/value pair string from the Request.QueryString object (via the .ToString() method). However that functionality isn’t the same for a generic NameValueCollection object (of which Request.QueryString is derived from).

So how do you take a NameValueCollection object and get a nicely formatted key/value pair string? (i.e. “key1=value1&key2=value2“) … Here’s a method I wrote a while ago:

/// <summary>
/// Constructs a QueryString (string).
/// Consider this method to be the opposite of "System.Web.HttpUtility.ParseQueryString"
/// </summary>
/// <param name="nvc">NameValueCollection</param>
/// <returns>String</returns>
public static String ConstructQueryString(NameValueCollection parameters)
{
	List<String> items = new List<String>();

	foreach (String name in parameters)
		items.Add(String.Concat(name, "=", System.Web.HttpUtility.UrlEncode(parameters[name])));

	return String.Join("&", items.ToArray());
}

Just in case you didn’t know about the System.Web.HttpUtility.ParseQueryString method, it’s a quick way of converting a query (key/value pairs) string back into a NameValueCollection.

Written by Lee Kelleher

June 6th, 2008 at 1:22 pm

Posted in blog

Tagged with , , , ,

Making Request.QueryString writable (by clone/copy)

without comments

Every now and then I completely forget that the Request.QueryString (and Request.Form) object is read-only. Today I had a bit of functionality where I needed to remove a key/value from the collection - but the Remove() method (of the NameValueCollection object) throws an exception.

Unfortunately, the Request.QueryString’s CopyTo method assigns the values to an ARRAY, not a NameValueCollection - losing functionality and flexibility.

You need to copy the Request.QueryString object to a new NameValueCollection instance, here’s how:

NameValueCollection qs = new NameValueCollection(Request.QueryString);

Now you can add/remove the key/values to your hearts content!

Oh, yeah, remember to import the System.Collections.Specialized namespace too!

Written by Lee Kelleher

June 6th, 2008 at 1:09 pm

Posted in blog

Tagged with , , , ,

Upgrade WordPress Shell Script

without comments

Now that I’ve found my new best friend (the sourcecode short-code), I want to put it to good use now.

Here’s a quick Unix shell script that I use to upgrade my WordPress installations:

#!/bin/sh
# WordPress Update Script
# Written by: Lee Kelleher
# Released: 2008-04-23
# Email: lee # at # vertino # dot # net
# Released under GPL

echo "Downloading current version of WordPress..."
wget http://wordpress.org/latest.tar.gz

echo "Uncompressing WordPress archive..."
tar -zxvf latest.tar.gz

echo "Removing downloaded archive..."
rm -f latest.tar.gz

echo "WordPress Upgrade complete!"

It’s a very very basic script… if you’re looking for something more user-friendly, (with back-ups), then either take a read of the WordPress Codex article, or download a better Unix shell script.

My version suits my purposes nicely.

Written by Lee Kelleher

April 23rd, 2008 at 11:41 am

Posting source code on WordPress.com

with one comment

I feel like a complete n00b … I’ve only just found out how to mark-up source-code snippets on WordPress.com

It’s in their FAQs: How do I post source code?

Essentially you use the short-code: [sourcecode language='css']…[/sourcecode]

Here’s an example:

// A "Hello World!" program in C#
class Hello
{
   static void Main()
   {
      System.Console.WriteLine("Hello World!");
   }
}

I knew about WP.org plugins that did this, but I’ve been scratching my head on how do this on WP.com for ages now!

Written by Lee Kelleher

April 23rd, 2008 at 9:55 am

Posted in blog

Tagged with , , , ,