C#

Improved Cascading Dropdowns With Blazor

calendar_today 05 July 2018 13:27

C# Blazor

In my last article, I looked at the experimental Blazor framework, using Cascading Dropdown Lists as an entry point. Since then, some feedback from Steve Sanderson to a question I asked has shown me a better way to implement this pattern.

Reading Text-based Files In ASP.NET

calendar_today 17 July 2015 13:43

C# General ASP.NET MVC ASP.NET Web Forms

Every time I need to work with the contents of text-based files in an ASP.NET application I invariably start off thinking about using the various static methods on the System.IO.File class to extract the text and then some string manipulation or Regex to parse the content into some kind of structure. And, just in time, I remember the TextFieldParser class that hides itself away in the Microsoft.VisualBasic assembly. The purpose of this article is to introduce this component to a wider audience, but also to serve me as an aide-mémoire in terms of the basic usage, which I always have to look up.

7 C# 6.0 Features That Every ASP.NET Developer Should Know About

calendar_today 14 April 2015 13:25

C# ASP.NET 5

Visual Studio 2015 introduces a completely new version of ASP.NET, but it also includes version 6 of the C# language. Previous new versions of C# have heralded substantial changes like the introduction of async and await in version 5, dynamic in version 4, LINQ in version 3 and so on. There are no major feature changes or introductions in version 6, but there are a number of syntactical improvements that you are likely to use on a daily basis. Here's a rundown of them.

Usage of the @ (at) sign in ASP.NET

calendar_today 22 January 2015 13:54

C# ASP.NET MVC ASP.NET Web Pages Razor

The number of places where you might use or encounter the @ sign in ASP.NET has grown over the last few years and its exact purpose in all circumstances still seems to cause confusion. Here's an overview of the most common places that it crops up, and guidance on its correct usage.

Book Review - CLR Via C# Third Edition

calendar_today 12 September 2010 08:14

C# General Book Review

I've had a review copy of Jeffrey Richter's CLR via C#, Third Edition for some months, and it has taken until now to get round to publishing my thoughts on the book. It's not my fault. I blame the book. It made me forget why I was given a copy in the first place. Let me explain...

Finding Yesterday in SQL and C#

calendar_today 12 July 2010 21:27

C# SQL

Here's something that comes up often in forums - How To Find Yesterday in SQL or C#. Piece of cake, if you know how, but tricky if you don't. And especially tricky to get the right value if you are not clear on the requirement.

Converting URLs Into Links With Regex

calendar_today 22 May 2010 22:56

C# Extension Method

Following on from the recent spate of extensions methods I've posted, here's another I use to convert URLs and email addresses into links within HTML. You may want to restrict users from submitting HTML tags via forms in your application, which means that URLs and email addresses that they submit appear as plain text unless they are subjected to some kind of processing.

Highlighting Keywords Found In Search Results

calendar_today 22 May 2010 19:41

C# ASP.NET 3.5 Extension Method ASP.NET Web Forms

A common question in the forums is how to highlight key words found in search results. Here's an extension method that does that, both for partial matches, or whole word matches.

Displaying The First n Characters Of Text

calendar_today 16 May 2010 09:59

C# ASP.NET 3.5 Extension Method

Displaying the first n characters of a block of text on a page without chopping words off halfway through is a common requirement. There are a number of ways to achieve this, but here's an extension method that you might find useful.

Using gacutil.exe and Reflection to generate the Exceptions Cheat Sheet

calendar_today 10 February 2010 07:28

C# Visual Studio General ASP.NET 3.5

The most recent addition to my Cheat Sheets features details of all the Exceptions that can be found in the most commonly used assemblies within ASP.NET development. Compiling this information was an interesting challenge. I could have simply copy-pasted from MSDN, but that would have been extremely tedious. Instead, I ended up with a blend of Linq to XML, Reflection, a dash of Regex and the Global Assembly Cache Tool - gacutil.exe. Here's the full story.

Cheat Sheet - .NET Framework Exceptions

calendar_today 07 February 2010 17:19

C# General ASP.NET 3.5

Here's a list of Exceptions that can be found in the assemblies which are most commonly used in ASP.NET development.  Ideally, you should be as specific as possible when catching or throwing Exceptions. The more specific you are, the less work the CLR has to do in locating the appropriate catch block, and the more informative your error messages are, which should help speed up identifying the source of any problems.

Parameterized IN clauses with ADO.NET and LINQ

calendar_today 28 September 2009 21:53

C# ADO.NET LINQ ASP.NET 3.5

Since my article on using parameters for Preventing SQL Injection In ASP.NET, I have had a few emails asking how to do the same with an IN clause expression. In this entry, I explore a couple of ways to do this.

Upload and Crop Images with jQuery, JCrop and ASP.NET

calendar_today 05 January 2009 13:54

C# AJAX Javascript ASP.NET 3.5 jQuery

I got given jQuery In Action for Christmas. By nature, I'm kind of a late adopter, and I'm already regretting this fact. jQuery has been around for some time, and I wished I had looked at it sooner. It's a fantastic library that really simplifies Javascript development, and is already attracting a goodly number of plug-ins. JCrop is one such, and while it hasn't yet reached version 1.0, it is remarkably easy to use as a web based image cropper. Here's how to put jQuery, JCrop and a FileUpload control together to allow users to upload images and crop them.

Delegates, Anonymous Methods and Lambda Expressions in C#

calendar_today 07 December 2008 19:33

C# ASP.NET 3.5

Delegates in C# cause a fair amount of confusion, but with the introduction of LINQ to SQL and the profilic use of the Lambda Expression operator (=>) that it has foisted on an unprepared batch of beginners, an understanding of how these two items are related, together with Anonymous Methods becomes more important. Most definitions of Delegates that you find start off with comparing them to "function pointers in C or C++", which is great if you ever worked with those languages and understood them, but not helpful to new programmers. Here's my attempt at simplifying the various concepts.

iTextSharp - Page Layout with Columns

calendar_today 24 November 2008 07:41

C# ASP.NET 3.5 iTextSharp

I have now covered many of the basics involved in generating PDF files from ASP.NET using iTextSharp in the series of articles listed below. This article will look at additional ways to provide formatting to documents through the use of columns.

iTextSharp - Drawing shapes and Graphics

calendar_today 17 November 2008 12:30

C# ASP.NET 3.5 iTextSharp

The previous iTextSharp article looked at bringing images into a PDF file and working with them. Sometimes, however, you may want to draw shapes and lines within the PDF and not rely on images. iTextSharp includes a lot of functionality that covers simple drawing to quite complex shapes. This article gets you started. Previous articles are listed below:

iTextSharp - Working with images

calendar_today 07 November 2008 23:00

C# ASP.NET 3.5 iTextSharp

The seventh article in my iTextSharp series looks at working with images. This article builds on the previous six which are listed below.

iTextSharp - Introducing Tables

calendar_today 03 November 2008 07:34

C# ASP.NET 3.5 iTextSharp

Tables will probably be one of the most used elements in PDFs generated from ASP.NET applications to provide the structure for documents such as orders and invoices. This overview is not an exhaustive examination of tables, but provides an introduction to working with them through iTextSharp, and builds on the previous articles in this iTextSharp series:

Book Review - Beginning ASP.NET 3.5 in C# and VB

calendar_today 26 October 2008 11:01

C# VB.Net ASP.NET 3.5 Book Review

Over the years, I have picked up and read many Beginners books that attempt to get someone started on the road to building web sites with ASP.NET. Nearly all of them assumed that their readers know more than they might. Some of them seem to assume that all readers are upgrading from one version of the .NET framework to another, while others assume that you already know about core web development technologies such as HTML, CSS, C# or VB etc. I well remember being frustrated with my first book, in that it didn't give me enough basic information to get started with web development, let alone web development with ASP.NET. Now, up steps Imar Spaanjaars, with his effort: Beginning ASP.NET 3.5 in C# and VB (Wiley/Wrox, ISBN: 978-0-470-18759-3).

iTextSharp - Links and Bookmarks

calendar_today 23 October 2008 21:51

C# ASP.NET 3.5 iTextSharp

Interactivity within PDF documents is enabled though Anchors (links) and Bookmarks. Following earlier articles in my iTextSharp series, this particular contribution will introduce the basics of linking and bookmarking PDF documents created via iTextSharp. You may want to review earlier articles in this series, if you haven't already done so.

Lists with iTextSharp

calendar_today 20 October 2008 08:32

C# ASP.NET 3.5 iTextSharp

Having already looked at how to create a PDF document with iTextSharp, set fonts and their styles and add text, this article turns its attention to lists. Ordered and unordered lists will be covered. You may want to review earlier articles in this series, if you haven't already done so.

iTextSharp - Adding Text with Chunks, Phrases and Paragraphs

calendar_today 18 October 2008 22:32

C# ASP.NET 3.5 iTextSharp

This is the third in a series of articles that looks at using the open source component, iTextSharp from within ASP.NET to generate PDFs. Just as HTML and ASP.NET provide containers for varying ampounts of textual content, iTextSharp offers the Chunk, Phrase and Paragraph classes. Before going on, if you would like to read earlier articles, they are:

iTextSharp - Working with Fonts

calendar_today 15 October 2008 22:07

C# ASP.NET 3.5 iTextSharp

Following on from my introduction to iTextSharp, the free PDF utility that lets you work with PDF files within ASP.NET, this article looks at working with fonts in PDF documents that you create. If you haven't read the first article in this series, I recommend that you do so now.

A more efficient RSS feed with C#

calendar_today 06 June 2007 23:15

C# ASP.NET 2.0

The contents of an RSS feed only change when items that appear in it are added or amended, so the feed created in the previous article (Create an RSS Feed In ASP.NET 2.0 C#) is rather inefficient, in that the output is generated everytime the feed is requested. Here's an improvement.

Basic file management with System.IO in ASP.NET

calendar_today 29 May 2007 12:37

C# ASP.NET 2.0

Some basic file and folder management tasks that require the use of classes inside System.IO

VBScript to C# - Equivalent string functions

calendar_today 28 May 2007 21:18

VBScript C#

A Cheat Sheet containing the VBScript string functions and their equivalent methods in C#.

C# Regular Expressions - the basics

calendar_today 24 May 2007 22:01

C#

The is a brief overview of the main classes and methods in the System.Text.RegularExpressions namespace. It doesn't cover Regex patterns in any real depth at all, but gives an introduction to the power of regular expressions using C#.

How to read a remote web page with ASP.NET 2.0

calendar_today 21 May 2007 21:38

C# ASP.NET 2.0

Two classes in the System.Net namespace make it very easy to obtain the html of a remote web page. These are the HttpWebRequest and HttpWebResponse. Here's a quick demo.

Splitting strings with C# and VB.NET

calendar_today 20 May 2007 20:21

C# VB.Net

Examples of splitting strings into arrays using C# and VB.Net, both with the String.Split() method, and the Regular Expressions Split() method.

C# Regular Expressions Cheat Sheet

calendar_today 19 May 2007 20:36

C#

Cheat sheet for C# regular expressions metacharacters, operators, quantifiers etc

Programmatically accessing data from DataSource controls

calendar_today 16 May 2007 10:06

C# ASP.NET 2.0 ADO.NET

For the main part, the DataSource controls are incredibly easy to work with. You just drag them onto your page in Design View, wire them up to a connection and provide some kind of command (ad hoc sql query or the name of a stored procedure - saved query in Access), then link them to a databound control on the page using its DataSource property. Then you run the page and all your data appears. But what if you want to get at one or more values from the returned data to do something else with it, like display it in a control that doesn't expose a DataSource property?

Send form content by email in ASP.NET

calendar_today 10 May 2007 22:53

C# ASP.NET 2.0 VB.Net

Using ASP.NET to send the contents of a form by email is a common requirement. This sample looks at generating an email using System.Net.Mail in both plain text and html format from a very basic Contact Us form.

How to highlight a GridView's row on hover

calendar_today 06 May 2007 20:50

C# ASP.NET 2.0 Javascript

As the user hovers over each row, it becomes highlighted, with the help of a small amount of javascript.

How to make an ASP.NET Table row highlight and become clickable

calendar_today 06 May 2007 20:38

C# ASP.NET 2.0 Javascript HTML

For those people who like to output their data to an asp:Table, highlighting the entire row and making it clickable can make it obvious to the user that some action is expected from them. This emulates the behaviour that can be found in some desktop applications. All that's needed for this is a bit of javascript, and the use of AddAttributes() for the table rows.

Getting various bits of URL with C#

calendar_today 27 April 2007 21:49

C# ASP.NET 2.0

Need some bit or all of the URL for any reason?

Paging long articles in ASP.NET using C#

calendar_today 09 April 2007 21:44

C# ASP.NET 2.0

Long articles are better broken into bite-sized chunks over several pages. With static HTML, this is easily achieved by dividing the article into logical separations and creating separate .htm files for each. Here's how to do it using C# for an article that gets posted to a database.

Date Formatting in C#

calendar_today 08 April 2007 21:11

C# ASP.NET 2.0

Cheat sheet detailing formatting options for dates and times in C#.

How to retain carriage returns or line breaks in an ASP.NET web page

calendar_today 06 April 2007 19:55

C# ASP.NET 2.0 HTML

Many newcomers to web development cannot get their head around why the carriage returns they made in their data on input from a textarea, or from a text file, Excel spreadsheet etc. do not appear when the web page renders.

Create an RSS Feed In ASP.NET 2.0 C#

calendar_today 05 April 2007 22:37

C# ASP.NET 2.0

Using the XmlTextWrite to output an XML file that serves as an RSS feed.

Create A Utility Class Containing Site-Wide Functions

calendar_today 03 April 2007 21:33

C# ASP.NET 2.0

In Classic ASP, the typical model for managing site-wide functions is to create one or more server-side includes containing libraries of code. The OOP nature of ASP.NET offers a much more elegant solution.