William Duffy

Glasgow Based C# ASP.NET Web Developer

Post archive for ‘ASP.NET’

How to consume an XML feed in ASP.NET – RSS

XML is the standard for distributing content on the internet, however it can prove a challenge when trying to consume and handle the data retrieved from an XML document. This is the first in a two part series on consuming and displaying XML content on your own website. We will be using XPathDocument and XPathNavigator [...]

Parsing dates when ASP.NET’s DateTime.Parse doesn’t work

Has DateTime.Parse ever thrown the following exception when you passed it a legally formatted value, leaving you bemused as to why it can’t parse it? String was not recognized as a valid DateTime As powerful as DateTime.Parse is, it cannot handle every representation of a date/time value without a little help from you, the developer. [...]

ASP.NET Request.Querystring with escaped ampersands

Take the following url “/images/myimage.jpg&width=300″. URL Encoding has no support whatsoever for HTML Encoding so passing an escaped ampersand html entity though a url in this format is illegal. Now, you may well be thinking “Hold on a minute William, I need to escape my ampersands to have valid XHTML markup on my pages”. Your [...]

ASP.NET’s Image Upload Filetype Validation

ASP.NET’s file upload facility offers a quick, easy method for allowing users to upload content to your server. In many cases however the upload type must be restricted. For example, perhaps you are allowing users to upload a profile image. You certainly don’t want them to be capable of uploading an executable (.exe) file! The [...]

Monitoring Database Connections

If you don’t close your database connections you can take down your server in a few minutes, that’s fact! But closing database connections is something that beginners can very easily forget. Here I will show you how to monitor database connections to SQL Server and ensure that your code is not draining the connection pool [...]

Coalesce: ASP.NET Strings

In programming it is a common occurrence to have a list of possiblities from which you would like the first available option selected. SQL Server has a handy method (Coalesce) which makes performing this easy, but unless you are using nullable types .NET does not have a suitable alternative. Here, I will make a helper [...]

ASP.NET’s “Internet Url” Regular Expression Validator

The regular expression validator is a great tool when a fast, robust, content validator is required. Drop it on the page, choose it’s ControlToValidate and give it an expression to match against the specified control’s content. There are even built in expressions to choose from….one of which is “Internet URL”. The problem with this is [...]

Retaining Anchor Position on ASP.NET Postback

I ran into a small problem the other day that although annoying, proved easy enough to fix. The problem arose because I was using JQuery UI tabs to allow multiple pageable gridviews to be managed on the one page. Whenever the gridview was paged a postback was initiated and the gridview paged as expected, however [...]