# Monday, June 01, 2009

Checking a string for illegal characters using Regular Expressions

In our Maine Microsoft Certification Study Group we recently had a discussion about using regular expression. Today I found myself writing a RegEx to check for illegal characters in a formula (string). I thought I’d share the solution:

private bool FormulaContainsIllegalCharacters( string formula )

{

    bool result = false;

    try

    {

        Regex r = new Regex( @"(!)|(@)|(#)|(\$)|(%)|(&)" );

        result = r.Match( formula ).Success;

    }

    catch { } // ignore any regular expressions errors -> return false

    return result;

}

In my case I’m not interested in handling exceptions. If a technical error occurs I will accept the input. Notice that I needed to put a “\” before the $ sign, since the $ is a reserved character marking the end of a line.
I don’t need to put each character in “( )” brackets, but for personal preference I just find it easer to read.

#    Comments [0] |
# Friday, May 29, 2009

ASCII table

Whenever I need one I always need search for a good ASII table.

So here is one:

Decimal Hex Unicode Description Character Entity Name Key
000 00 0000 null [nul] Ctrl-@
001 01 0001 start of heading [soh] Ctrl-A
002 02 0002 start of text [stx] Ctrl-B
003 03 0003 end of text [etx] Ctrl-C
004 04 0004 end of transmission [eot] Ctrl-D
005 05 0005 enquiry [enq] Ctrl-E
006 06 0006 acknowledge [ack] Ctrl-F
007 07 0007 bell [bel] Ctrl-G
008 08 0008 backspace [bs] Ctrl-H
009 09 0009 horizontal tab [ht] Ctrl-I
010 0A 000A new line, line feed [nl] Ctrl-J
011 0B 000B vertical tab [vt] Ctrl-K
012 0C 000C form feed, new page [ff] Ctrl-L
013 0D 000D carriage return [cr] Ctrl-M
014 0E 000E shift out [so] Ctrl-N
015 0F 000F shift in [si] Ctrl-O
016 10 0010 data link escape [dle] Ctrl-P
017 11 0011 device control 1 [dc1] Ctrl-Q
018 12 0012 device control 2 [dc2] Ctrl-R
019 13 0013 device control 3 [dc3] Ctrl-S
020 14 0014 device control 4 [dc4] Ctrl-T
021 15 0015 negative acknowledge [nak] Ctrl-U
022 16 0016 synchronous idle [syn] Ctrl-V
023 17 0017 end of trans. block [etb] Ctrl-W
024 18 0018 cancel [can] Ctrl-X
025 19 0019 end of medium [em] Ctrl-Y
026 1A 001A substitute [sub] Ctrl-Z
027 1B 001B escape [esc] Ctrl-[
028 1C 001C file separator [fs] Ctrl-\
029 1D 001D group separator [gs] Ctrl-]
030 1E 001E record separator [rs] Ctrl-^
031 1F 001F unit separator [us] Ctrl-_
032 20 0020 Space Space
033 21 0021 Exclamation mark !
034 22 0022 quotation mark " "
035 23 0023 Number sign #
036 24 0024 Dollar sign $
037 25 0025 Percent sign %
038 26 0026 Ampersand & &
039 27 0027 Apostrophe '
040 28 0028 Left parenthesis (
041 29 0029 Right parenthesis )
042 2A 002A Asterisk *
043 2B 002B Plus sign +
044 2C 002C Comma ,
045 2D 002D Hyphen -
046 2E 002E Period (fullstop) .
047 2F 002F Solidus (slash) /
048 30 0030 0 0
049 31 0031 1 1
050 32 0032 2 2
051 33 0033 3 3
052 34 0034 4 4
053 35 0035 5 5
054 36 0036 6 6
055 37 0037 7 7
056 38 0038 8 8
057 39 0039 9 9
058 3A 003A Colon :
059 3B 003B Semi-colon ;
060 3C 003C less-than sign < &lt;
061 3D 003D Equals sign; =
062 3E 003E greater-than sign > &gt;
063 3F 003F Question mark ?
064 40 0040 Commercial at @
065 41 0041 A A
066 42 0042 B B
067 43 0043 C C
068 44 0044 D D
069 45 0045 E E
070 46 0046 F F
071 47 0047 G G
072 48 0048 H H
073 49 0049 I I
074 4A 004A J J
075 4B 004B K K
076 4C 004C L L
077 4D 004D M M
078 4E 004E N N
079 4F 004F O O
080 50 0050 P P
081 51 0051 Q Q
082 52 0052 R R
083 53 0053 S S
084 54 0054 T T
085 55 0055 U U
086 56 0056 V V
087 57 0057 W W
088 58 0058 X X
089 59 0059 Y Y
090 5A 005A Z Z
091 5B 005B Left square bracket [
092 5C 005C Reverse solidus (backslash) \
093 5D 005D Right square bracket ]
094 5E 005E Caret ^
095 5F 005F Horizontal bar (underscore) _
096 60 0060 Acute accent `
097 61 0061 a a
098 62 0062 b b
099 63 0063 c c
100 64 0064 d d
101 65 0065 e e
102 66 0066 f f
103 67 0067 g g
104 68 0068 h h
105 69 0069 i i
106 6A 006A j j
107 6B 006B k k
108 6C 006C l l
109 6D 006D m m
110 6E 006E n n
111 6F 006F o o
112 70 0070 p p
113 71 0071 q q
114 72 0072 r r
115 73 0073 s s
116 74 0074 t t
117 75 0075 u u
118 76 0076 v v
119 77 0077 w w
120 78 0078 x x
121 79 0079 y y
122 7A 007A z z
123 7B 007B Left curly brace {
124 7C 007C Vertical bar |
125 7D 007D Right curly brace }
126 7E 007E Tilde ~
127 7F 007F delete [del]
#    Comments [0] |
# Thursday, May 28, 2009

Software Development Event on June 26th in Hotel Houten te Houten (Netherlands)

On June 26th the SDN will organize it’s quarterly Software Development Event in Hotel Houten (te Houten) in the Netherlands.

The speaker line-up is awesome (as usual), don’t miss it!

Sessions:

9:00 - 10:15

iPhone Development for .NET Developers

Kevin McNeish

.NET

 

Agile anti-patterns. Yes, agile projects can fail too.

Sander Hoogendoorn

AR

 

10 Tips to make your Delphi Win32 App .NET Ready

Michael Li

Delphi

 

Advanced DotNetNuke Module Development

Mitchel Sellers

DNN

 

MythBusters – debunking common SharePoint Farm Misconceptions

Spencer Harbar

IW

 

Van concept naar productie met Expression Blend 3

Martin Tirion

UX

10:45 - 12:00

Design by Contract in .NET

Pieter Joost van de Sande

.NET

 

Working with Expression Blend to Build World Class User Interfaces

Kevin McNeish

.NET

 

HYPER V/SharePoint How to create a proper lab

Bob Fox

AR

 

ASP.NET Development met Delphi Prism

Bob Swart

Delphi

 

Creating a DotNetNuke Authentication Provider

Mitchel Sellers

DNN

 

Waarom SharePoint Application Pages?

Robin Meuré

IW

13:00 - 14:15

Windows Azure

Dennis van der Stelt

.NET

 

Sessie nog onbekend

Spreker Onbekend

AR

 

De toekomst van hardware

Dick van Es

CS

 

ER/Studio for Delphi Developers

Michael Li

Delphi

 

Kerberos Part 1: no ticket touting here. Does SharePoint add another head?

Spencer Harbar

IW

 

Wat is Silverlight 3?

Koen Zwikstra

UX

14:30 - 15:45

A Lap Around VSTS 2010

Hassan Fadili

.NET

 

Learning from the iPhone: Building World-Class .NET User Interfaces

Kevin McNeish

.NET

 

Model driven development for the cloud

Erik van de Ven

AR

 

Reduce, re-use, recycle

Gert Hekkenberg

CS

 

SQL Server Performance en Tuning

Peter ter Braake

DB

 

Building a Silverlight module

Stefan Kamphuis

DNN

16:15 - 17:30

SQL Data Services & Silveright 3

Dennis van der Stelt

.NET

 

Unix/Linux vs NonStop

Diederick de Buck

CS

 

Spatial Data Types: SQL Server 2008 als navigator.

Henk van Galen

DB

 

Delphi 2009 IDE for Delphi 5-6-7.x developers

Michael Li

Delphi

 

Creating a DotNetNuke Membership Provider

Mitchel Sellers

DNN

 

Kerberos Part 2: Advanced Scenarios and additional considerations.

Spencer Harbar

IW

 

Sign up here: www.sdn.nl/sde

#    Comments [5] |

Maine Quality Forum

As owner of Develop-One I’m proud to announce that the Maine Quality Forum is now being hosted and serviced by Develop-One.

Visit the Maine Quality Forum site here.

#    Comments [0] |
# Wednesday, May 27, 2009

Rounding decimals to X positions

Another little extension method. This one allows easy rounding to a specific number of decimals:

double d = 0.66782423;
string s = d.ToString(3);  // s = “0.668”

This is done by the following method:

 

public static class DoubleExtension

{

    public static string ToString( this double value, int decimals )

    {

        StringBuilder format = new StringBuilder( "0" );

        if ( decimals > 0 )

        {

            format.Append( "." );

        }

        for ( int i = 0; i < decimals; i++ )

        {

            format.Append( "0" );

        }

        return value.ToString( format.ToString() );

    }

}

#    Comments [0] |

ReportViewer Control in Visual Studio 2008

I’ve been working a lot with the ReportViewer Control in Visual Studio 2008. The greatest part of the control is that you can implement reporting without using a database!

ReportViewer Control in Visual Studio 2008

ReportViewer is a freely redistributable control that enables embedding reports in applications developed using the .NET Framework. Reports are designed with drag-and-drop simplicity using Report Designer included in Visual Studio 2008 (Standard editon and above.)

See screenshots of some applications that have ReportViewer control embedded in them.

The ReportViewer control offers the following benefits:

  • Processes data efficiently. The reporting engine built into ReportViewer can perform operations such as filtering, sorting, grouping and aggregation.
  • Supports a variety of ways in which to present data. You can present data as lists, tables, charts and matrices (also known as crosstabs.)
  • Adds visual appeal. You can specify fonts, colors, border styles, background images etc to make your report visually appealing.
  • Enables interactivity in reports. You can have collapsible sections, document map, bookmarks, interactive sorting etc in your report.
  • Supports conditional formatting. You can embed expressions in the report to change display style dynamically based on data values.
  • Supports printing and print preview.
  • Supports export to Excel and PDF.

The control can process and render reports independently using a built-in engine ('local mode') or it can display reports that are processed and rendered on a Report Server ('remote mode').

There is a WinForms and a WebForms version of the control.

 

Excellent tutorials on ReportViewer can be found at: http://www.gotreportviewer.com/

#    Comments [0] |

Convert DateTime to DateTime?

Back when .NET 1.1 was cool people would often use DateTime.MinValue to indicate that a date was actually empty. With .NET 2.0 can the Nullable<T> which allows you to create a nullable datetime. Ofcourse there is still plenty of old code out there, so when adding new code you may need to convert DateTime.MinValue to null. With extensions methods (.NET 3.5) you can implement an elegant solution.

The code below will allow you to write this:

DateTime old = DateTime.MinValue;

DateTime? current = old.ToNullable();

This is achieved with the following extension method:

public static class DateTimeExtension
{
    /// <summary>
    /// Examine the value of the DateTime, if the value is equal to DateTime.MinValue
    /// then the result is null, otherwise the supplied value is returned.
    /// </summary>
    /// <param name="value"></param>
    /// <returns></returns>
    public static DateTime? ToNullableDateTime( this DateTime value )
    {
        if ( value == DateTime.MinValue )
        {
            return null;
        }
        else
        {
            return value;
        }
    }
}

#    Comments [0] |
# Tuesday, May 26, 2009

Registration for SDN Conference 2009 | OpenForce ’09 Europe is now open!

The leading event for C#, VB.Net, ASP.NET, DotNetNuke and Delphi developers is now open for registration!

 

For the 18th year running the Software Development Network will organize this 2 day event (on October 19th and 20th, 2009) with sessions about :

  • .NET (C#, VB.Net, F#, etc.)
  • User eXperience (ASP.Net, Silverlight, Expressions, Flash, etc.)
  • Information Worker (MOSS, BizTalk, OBA, etc.)
  • DotNetNuke (OpenForce Europe ’09 conference)
  • Delphi
  • Architecture
  • Core Systems (C, Cobol, NonStop, IDMS, PL/1, DB2, CICS, TSO, ISPF, etc.)
  • Databases

Don’t miss out! Click here to register.

#    Comments [0] |
# Monday, May 18, 2009

Visual Studio 2010 and .NET FX 4 Beta 1 available for download

hero_2010_v3

Visual Studio 2010 and .NET FX 4 Beta 1 are available for download from the MSDN Subscriber Downloads as of today.

Go to: VS2010 Beta 1 Download for MSDN

The 5 page factsheet for VS2010 can be found here.

#    Comments [0] |
# Wednesday, April 29, 2009

Ireland Environmental Services is now online

Here is a shameless plug for my friend Mike who now has his own website at www.ireland-environmental.com.

If you need environmental services or help with getting the right permits to do construction and such, then Ireland Environmental Services is the place to go.
Mike is running a blog on environmental issues too, visit it here.

#    Comments [0] |
# Friday, April 24, 2009

Random filename

Today I had to fix a bug in some code involving a program creating multiple files where each file needed to have a unique machine generated filename. I was building my own unique name using the DateTime.Now.Ticks().ToString() as part of the name. Apparently on some machines the Ticks are not going to be unique. So I looked at the Path.GetTempFile() method, but I needed to control the location of the temporary files. Next stop: Path.GetRandomFileName().

Documentation:
The GetRandomFileName method returns a cryptographically strong, random string that can be used as either a folder name or a file name. Unlike GetTempFileName, GetRandomFileName does not create a file. When the security of your file system is paramount, this method should be used instead of GetTempFileName.

Works great!

#    Comments [0] |
# Tuesday, April 21, 2009

Windows Live Groups and Time Zones

We (the Maine Microsoft Certification Study Group) has been using Windows Live Groups as our virtual place to hang out. Out weekly meeting is posted on the group calendar, but the times kept showing up wrong on the overview page. As it turns out (thanks to Winston Natoli) there are three places where you can set the timezone:

Group Time Zone
- <Select Group or Access via Group Url>/ Options / Group Options/ General
Calendar Time Zone
<calendar.live.com>/ Options/ More Options / Time Zone
Live ID
<account.live.com>/ Registered Information/ Home Location/ Time Zone

 

After setting all of them to EST I’m now getting the right information.

#    Comments [0] |
# Monday, April 06, 2009

Training Kit now on sale at Amazon.com

Yeah, my last Training Kit is shipping!

Get a copy now at Amazon: http://tinyurl.com/dxwdz5

#    Comments [0] |
# Monday, March 23, 2009

Entity Framework: ObjectContext.SaveChanges is transactional

The documentation doesn't specifiy it but in the Entity Framework when you call ObjectContext.SaveChanges the update is 'wrapped' in a transaction.

NorthwindIBModel model = new NorthwindIBModel();

Guid id = Guid.NewGuid();

model.AddToCustomer(new Customer() { CustomerID = id, ContactName = "Andrew", CompanyName = "Northwind Traders" });
model.AddToCustomer(new Customer() { CustomerID = id, ContactName = "Aikido", CompanyName = "Northwind Traders " });

model.SaveChanges(); // exception duplicate key - transactional -> no changes to the database

#    Comments [0] |

Resetting Visual Studio

Today I ran into a problem where apparently the registry settings for Visual Studio got messed up since I was no longer able to add a data connection in my Server Explorer, nor create an Entity Framework model from a database. Time to reset Visual Studio command(o) style.

To reset Visual Studio you open the Visual Studio Command Prompt and type:

devenv /resetsettings

And life is good...

#    Comments [0] |
# Tuesday, March 17, 2009

Code Camp 11: Developer Stimulus Package

CodeCamp

Just a quick reminder to all that Code Camp 11: Developer Stimulus Package will be held on March 28th, 2009. The Boston code camp will be held at the Microsoft Waltham, MA office and the session lineup is looking great!

More info: http://www.thedevcommunity.org/Events/PresentationList.aspx?id=11

#    Comments [0] |
# Thursday, March 12, 2009

Upcoming BAND Gig: A Look at a Real World .NET MVC Implementation

On March 24th the Bangor .NET Developers will host an Ineta sponsored event where Steve Andrews will do a talk about the ASP.NET MVC Framework.

The ASP.NET MVC Framework provides a powerful Model View Controller (MVC) approach to building web applications, and provides separation of concerns, increased testability, control over HTML output, and intuitive URLs. We will start by looking at building a model framework with LINQ to SQL, including validation and model binding. Then, we'll explore a custom generics-based repository and services implementation. Finally, we'll tie it all together with a look at Views and jQuery.

 

Steve Andrews is a Team System MVP and INETA speaker, and has been working as a developer for more than 9 years. During this time, he has designed and developed applications in such widely varying areas as trust accounting, medical information management, supply chain management, and retail systems. Steve is also a MCTS, ICSOO, and community fanatic.

 

Go to www.bangordevelopers.com to sign up now.

#    Comments [2] |
# Monday, March 09, 2009

SDN Event on March 30th in Hotel & Congrescentrum "De Bergse Bossen" (The Netherlands)

The combined user groups of the SDN are putting together a terrific one day event with great sessions for software developers, architects, information workers and database professionals. Don't miss it!

Here is an overview of the sessions:

image

Go to www.sdn.nl/sde to sign up!

#    Comments [0] |

developer.Equals( otherDeveloper );

It often seems that management believes developers are highly exchangeable. Is an experienced developer leaving the team?

Then just new up a new .NET developer and you're done. This Dilbert episode reminded me of that attitude.


From www.dilbert.com

#    Comments [0] |
# Monday, February 16, 2009

MSDN Roadshow is coming to Augusta

Roadshow.pngOnce again the Maine Developer Network (thanks to John, Shawn and the State of Maine Government) is happy to help out Chris, Bob and Jim with finding a location to hold the MSDN Northeast Roadshow.

On March 19th the Roadshow will hit the Central Maine Commerce Center in Augusta. Go here to sign up today!

Location
Central Main Commerce Center
Florian Auditorium
500 Civic Center Drive Augusta Maine 04330
United States

Date
Thursday, March 19, 2009 8:30 AM - Thursday, March 19, 2009 4:00 PM Eastern Time (US & Canada)
Welcome Time: 8:00 AM

#    Comments [0] |