When you start off by telling those who disagree with you that they are not merely in error but in sin, how much of a dialogue do you expect? --Thomas Sowell
Welcome to my blog and project site for Microsoft.NET development.

I've been a full time .NET developer for ten years, but I didn't start my professional life as a programmer ... more
Share/Print this page:

Category: Snippet

article types
snippet
[Articles: 28]

Sort:Most RecentUpdatedAuthorPagesViews TodayTotal Views 

Convert String to Int in C#

By steve on November 05, 2011.  |  Updated on January 22, 2012.  |  418 views, 1 today.  |  1 page.
 .NET  C#  Conversions  Data Types  Snippet  Text and Strings 
Three different ways to convert a string to an integer in C# and the pros and cons of each.

How to scrape or download a webpage using C#

By ktb on March 05, 2007.  |  Updated on January 22, 2012.  |  31,969 views, 25 today.  |  1 page.
 ASP.NET  C#  Snippet  Web 
A quick and dirty snippet for the basic approach to scraping the HTML content from a webpage programmatically.

How Do I Read a File As an Array of Bytes in C#

By steve on February 16, 2007.  |  Updated on January 22, 2012.  |  24,850 views, 83 today.  |  1 page.
 .NET  C#  IO  Snippet 
Learn how to use a stream to read the byte content of a file. You can also use the new ReadAllBytes method on the File class.

How to Deliver a File From ASP.NET and Specify Its MIME Type

By steve on February 15, 2007.  |  Updated on January 22, 2012.  |  8,351 views, 5 today.  |  2 pages.
 ASP.NET  Policy and Standards  Reference  Snippet  Web 
Learn how to use ASP.NET to dynamically return a file to the user and the importance of MIME types in this process.

Online Random Number Generator

By steve on February 14, 2007.  |  Updated on January 22, 2012.  |  10,381 views, 4 today.  |  1 page.
 C#  Data Types  Has Downloads  Has Images  Math and Statistics  Snippet 
Need random numbers? Learn more about our online generator of random numbers.

PathHelper - Convert File and Folder Paths and URLs in an ASP.NET Application

By steve on February 13, 2007.  |  Updated on January 22, 2012.  |  21,800 views, 8 today.  |  2 pages.
 ASP.NET  C#  Has Downloads  Has Images  Snippet 
Managing all the various types of paths in ASP.NET can be a chore. You have URLs, virtual paths, absolute paths, relative paths and application paths. This article helps you make sense of all of these while managing conversions and getting the type of path you need when you need it.

How do I get the application path in an ASP.NET application?

By steve on February 13, 2007.  |  Updated on January 22, 2012.  |  88,204 views, 87 today.  |  1 page.
 ASP.NET  Conversions  Snippet 
A simple snippet to show you how to get the virtual application path which is relative to the root of the website.

Extract Keywords from a Search String in C#

By steve on January 27, 2007.  |  Updated on January 22, 2012.  |  28,547 views, 12 today.  |  1 page.
 .NET  C#  Has Downloads  Has Images  Regular Expressions  Snippet  Text and Strings 
A better way than String.Split to extract words from a string.

How Can I Use Javascript to Allow Only Numbers to Be Entered in a TextBox?

By steve on January 11, 2007.  |  Updated on January 26, 2012.  |  267,991 views, 446 today.  |  1 page.
 Client side  HTML  Javascript  Snippet  Web Browsers 
An easy javascript code snippet to allow only digits to be typed in a text box. Includes interactive demonstration.

How Do I Suppress a Keystroke in a Browser Input Box Using Javascript?

By steve on January 11, 2007.  |  Updated on January 22, 2012.  |  28,063 views, 9 today.  |  1 page.
 Client side  Javascript  Snippet  Web Browsers 
Learn how to use javascript to suppress a keystroke in a browser input box.

How Do I Keep My Website From Being Viewed In a Frame?

By steve on January 11, 2007.  |  Updated on January 22, 2012.  |  6,791 views, 3 today.  |  1 page.
 Client side  Javascript  Snippet  Web Browsers 
Learn how to keep your website from being viewed in a frame. This is not necessarily good practice, but it's needed in some instances.

How Can I Easily Manage an XML Configuration File in .NET?

By steve on January 10, 2007.  |  Updated on January 22, 2012.  |  40,061 views, 50 today.  |  1 page.
 .NET  C#  Data  IO  Snippet  XML 
.NET makes reading and writing XML as easy as pie. Use a class template and you never have to deal with XML at all.

How Do I Get Paths and URL fragments from the HttpRequest object?

By steve on January 09, 2007.  |  Updated on January 22, 2012.  |  81,987 views, 129 today.  |  1 page.
 ASP.NET  C#  Snippet  Web 
A reference for extracting URL and path information from the HttpRequest object in ASP.NET.

Using the HttpContext object

By steve on January 09, 2007.  |  Updated on January 22, 2012.  |  50,022 views, 22 today.  |  1 page.
 .NET  ASP.NET  C#  Server side  Snippet  Web 
Learn how you can get access to the HttpContext object when you're not in the code-behind of an ASPX page?

Extract Hex Digits From a String

By steve on January 09, 2007.  |  Updated on January 22, 2012.  |  10,021 views, 5 today.  |  1 page.
 .NET  C#  Conversions  Regular Expressions  Snippet  Text and Strings 
Learn how to extract hex digits from a string using C#. Useful for cases where you have dirty hex information or extra characters.

Parsing Email Addresses with Regular Expressions

By steve on January 09, 2007.  |  Updated on January 22, 2012.  |  82,470 views, 70 today.  |  1 page.
 .NET  C#  Email  Policy and Standards  Regular Expressions  Snippet 
Use C# to parse and validation email address. I present both a strict and lenient regular expression and discuss what constitutes a valid email address.

Parsing URLs with Regular Expressions and the Regex Object

By steve on January 09, 2007.  |  Updated on January 22, 2012.  |  47,605 views, 28 today.  |  2 pages.
 .NET  C#  Overview  Policy and Standards  Regular Expressions  Snippet  Text and Strings  Web 
Go in depth in understanding the structure of a URL or URI and see a single regular expression that can be used to extract the various pieces in one fell swoop.

Convert Integer To Enum Instance in C#

By steve on January 09, 2007.  |  Updated on January 01, 2012.  |  223,944 views, 103 today.  |  1 page.
 .NET  C#  Conversions  Enums  Snippet 
Sample C# code showing how to convert an integer to an instance of an enumeration.

Convert String to Enum Instance

By steve on January 09, 2007.  |  Updated on January 15, 2012.  |  186,699 views, 236 today.  |  1 page.
 .NET  C#  Conversions  Enums  Snippet  Text and Strings 
C# code sample showing how to convert a string to an instance of an enumeration.

Convert Hex String to .NET Color

By steve on January 09, 2007.  |  Updated on January 22, 2012.  |  95,701 views, 110 today.  |  1 page.
 .NET  C#  Conversions  CSS  HTML  Snippet 
Learn an easy way and a hard way to convert a hex string to a .NET color using C#.

Convert .NET Color to Hex String

By steve on January 09, 2007.  |  Updated on January 22, 2012.  |  41,616 views, 50 today.  |  1 page.
 .NET  C#  Conversions  CSS  HTML  Snippet 
Learn how to convert a hex string to a .NET color using C#.

Set Initial Focus on an ASP.NET Page

By steve on January 09, 2007.  |  Updated on January 22, 2012.  |  17,900 views, 6 today.  |  1 page.
 C#  Client side  Javascript  Snippet  Web  Web Browsers 
Here's a C# snippet to set the initial focus when a page loads. It takes into account some of the quirks with different types of controls and HTML elements.

C# StyleHelper Class

By steve on January 09, 2007.  |  Updated on January 22, 2012.  |  12,967 views, 5 today.  |  1 page.
 C#  CSS  Snippet  Web  Web Design 
While CSS is the preferred way to manage webpage styles these days, sometimes it's helpful to manage those styles programmatically.

C# RandomProvider Class

By steve on January 09, 2007.  |  Updated on January 22, 2012.  |  18,097 views, 13 today.  |  1 page.
 .NET  C#  Math and Statistics  Snippet 
I provide a class, RandomProvider, which provides random numbers for several of the .NET data types and based on statistical distributions.

C# StopWatch Class

By steve on January 07, 2007.  |  Updated on January 22, 2012.  |  45,530 views, 18 today.  |  1 page.
 .NET  C#  Performance  Snippet 
A high precision stop watch class for timing in your C# or .NET programs

Hexadecimal (Hex) to Decimal Lookup Table

By steve on January 07, 2007.  |  Updated on January 22, 2012.  |  130,623 views, 231 today.  |  2 pages.
 .NET  C#  Reference  Snippet  Web Design 
Convert hex to decimal. Convert dec to hexadecimal. This handy lookup table is a lot easier than punching it into your calculator.

Custom HyperLink Column for DataGrid

By steve on January 07, 2007.  |  Updated on January 22, 2012.  |  42,771 views, 23 today.  |  1 page.
 .NET Controls  C#  Data  Snippet  SQL Server 
Detailed example with code showing how to add a custom link column to a datagrid.

Adding Columns to DataGrid Programmatically

By steve on January 01, 2007.  |  Updated on January 22, 2012.  |  82,273 views, 50 today.  |  2 pages.
 .NET Controls  ASP.NET  C#  Data  Snippet  SQL Server 
Demonstration and code for programmatically adding a custom column to a DataGrid.