Regular Expressions

I use Emurasoft’s EmEditor as my preferred text editor, and wanted to find a way to identify non alphanumeric characters, including foreign characters.

After a bit of Googling, I found a regular expression to find characters in a range.

The regular expression below is used to find any characters betwen 0 and 127, which includes A-Z, a-z, 0-9, various symbols.

Plus 192 to 255, such as À to ÿ.


MVC Bootstrap Update breaks CSS


I recently updated all of the NuGet packages in one of my solutions, and it seemed to break the CSS.

I recreated the project and copied the model, controller and views across to the new project. I then updated the NuGet packages one by one, and when I updated to Bootstrap 4.0.0 (or later) it broke!

When I downgraded to 3.3.7 it all came back again 🙂

Therefore, it is probably outdated code in the MVC template in Visual Studio that causes the new bootstrap to break it.

Hopefully this will help other people having the same issue

Outlook: Prefixing .MSG (message) files with the date the e-mail was sent

I recently copied all my e-mails out of an archive folder, so I could zip them up on my hard drive. To do this I wanted to rename each file with the date the email was sent, using the format YYYY-MM-DD.

The VBA code below works for me 🙂

Please ensure you test any script taken from my website on a test/development machine, before running on a production server

Sub GetMessageDate()
    Dim OlApp As Outlook.Application
    Set OlApp = GetObject(, "Outlook.Application")
    Dim MsgFilePath
    Dim Eml As Outlook.MailItem
    Dim Path As String
    Path = "C:Outlook Files"
    If OlApp Is Nothing Then
        Err.Raise ERR_OUTLOOK_NOT_OPEN
    End If

    Dim fs As Object
    Set fs = CreateObject("Scripting.FileSystemObject")
    Dim temp As Object
    Set temp = fs.GetFolder(Path)
    For Each MsgFilePath In temp.files
        Set Eml = OlApp.CreateItemFromTemplate(Path & MsgFilePath.Name)
        'Now rename the file
        Name Path & MsgFilePath.Name As Path & Format(Eml.SentOn, "YYYY-MM-DD") & " " & MsgFilePath.Name
        Set Eml = Nothing
    Set OlApp = Nothing
End Sub

C#: Class to get the connection string for Entity Framework

using System;
using System.Data.SqlClient;
using System.Data.EntityClient;

using System.Globalization;
using System.Configuration;

namespace ProjectFrameworkLayer
    public class ProjectFrameworkLayerBase
        internal string GetEntityConnectionString()
            // Initialize the connection string builder for the underlying provider.
            SqlConnectionStringBuilder sqlBuilder =
                new SqlConnectionStringBuilder();

            string dataSource = ConfigurationManager.AppSettings["Entity_DataSource"].ToString(CultureInfo.InvariantCulture);
            string initialCatalog = ConfigurationManager.AppSettings["Entity_InitialCatalogue"].ToString(CultureInfo.InvariantCulture);
            bool integratedSecurity = Convert.ToBoolean(ConfigurationManager.AppSettings["Entity_IntegratedSecurity"]);

            // Set the properties for the data source.
            sqlBuilder.DataSource = dataSource;
            sqlBuilder.InitialCatalog = initialCatalog;
            sqlBuilder.IntegratedSecurity = integratedSecurity;

            if (!sqlBuilder.IntegratedSecurity)
                sqlBuilder.UserID = ConfigurationManager.AppSettings["Entity_UserName"].ToString(CultureInfo.InvariantCulture);
                sqlBuilder.Password = ConfigurationManager.AppSettings["Entity_Password"].ToString(CultureInfo.InvariantCulture);

            sqlBuilder.MultipleActiveResultSets = Convert.ToBoolean(ConfigurationManager.AppSettings["Entity_MultipleActiveResultSets"]);
            sqlBuilder.ApplicationName = ConfigurationManager.AppSettings["Entity_ApplicationName"].ToString(CultureInfo.InvariantCulture);

            // Initialize the EntityConnectionStringBuilder.
            EntityConnectionStringBuilder entityBuilder =
                new EntityConnectionStringBuilder();

            entityBuilder.Metadata = ConfigurationManager.AppSettings["Entity_MetaData"].ToString(CultureInfo.InvariantCulture);
            entityBuilder.ProviderConnectionString = sqlBuilder.ToString();
            entityBuilder.Provider = ConfigurationManager.AppSettings["Entity_ProviderName"].ToString(CultureInfo.InvariantCulture);

            return entityBuilder.ToString();

JavaScript: Show/Hide field

$(document).ready(function () {
    if ($("#ID").val() == "1") {
    else {
function ShowHideOther() {
    if ($("#ID").val() == "1") {
    else {


new { onchange = "ShowHideOther()" }

to the drop-down list definition in the view

MVC: Drop-down List

Populate the list of drop-down options (using “ID” and “Description”) from within the Controller:

ViewBag.DropDownOptions = new SelectList(

Then create a Drop-Down List within the View. Model.ID should refer to the source value, and then the list of options:

    model => model.ID, 

VB: Retrieve the header row column names from a text file

The code below is an example of how to retrieve the column/field names from the header row from a text file, and add them to a “ListBox”.

Please ensure you test any script taken from my website on a test/development machine, before running on a production server

Dim tfp As Microsoft.VisualBasic.FileIO.TextFieldParser
' Change "Filename.TXT" to the filename of your choice
tfp = My.Computer.FileSystem.OpenTextFieldParser("Filename.TXT")
' Identify the file type as Delimited
tfp.TextFieldType = FileIO.FieldType.Delimited

' Set the delimiter of the file.  In this example comma.
tfp.Delimiters = New String() {","}
' To set the delimiter to the pipe system, use:
'    tfp.Delimiters = New String() {"|"}
' or, for the Tab character, use:
'    tfp.Delimiters = New String() {vbTab}

' Does the file use quotes to enclose text values?
tfp.HasFieldsEnclosedInQuotes = True

' Declare a variable to store the current row
Dim cr() As String

' Loop through the lines within the file
While Not tfp.EndOfData
        ' Get the currentrow, and read the fields
        cr = tfp.ReadFields
        ' Declare a variable to store the current field
        Dim cf As String
        ' Loop through each field within the current row
        For Each cf In cr
    Catch malFormLineEx As Microsoft.VisualBasic.FileIO.MalformedLineException
        MessageBox.Show("Line " & malFormLineEx.Message & _
                        "is not valid and will be skipped.", _
                        "Malformed Line Exception")
    Catch ex As Exception
        MessageBox.Show(ex.Message & " exception has occurred.", _
        ' Close theOpenTextFieldParser
    End Try
End While

VB: The ‘Microsoft.Jet.OLEDB.4.0’ provider is not registered on local machine

I was in the middle of writing an application to retrieve the list of Access Database Tables, but I was getting the error “The ‘Microsoft.Jet.OLEDB.4.0’ provider is not registered on the local machine.”

I discovered, that as I was using Vista x64, I needed to change the “Advanced Compiler Options” in Visual Studio to target the “x86” CPU, thereby creating a 32-bit application.

Advanced Compiler Options

When I tried again, it worked