Microsoft Express

The link below takes you to the Microsoft Express products like Visual Basic Express 2008 and SQL Server Express 2008. http://www.microsoft.com/express/

Retrieving Command Line Parameters

Getting command line parameters or seeing if they are present is not as easy as you would think. I whipped up some code to make this flexible and easy.   Private Const ParameterPrefix As Char = "/"c          Private Function GetCommandLineArgument(ByVal parameter As String) As String      Dim paramValue = String.Empty      For Each tempValue As String In System.Environment.GetCommandLineArgs         If … Continue reading Retrieving Command Line Parameters

Serialize Your Objects to and from JSON

Here is some easy, generic code to serialize your objects to and from JSON:Public Shared Function JsonEncode(ByVal input As Object) As String Dim serilizer = New DataContractJsonSerializer(input.GetType) Using ms = New MemoryStream() serilizer.WriteObject(ms, input) Return Encoding.Default.GetString(ms.ToArray()) End UsingEnd FunctionPublic Shared Function JsonDecode(Of T)(ByVal input As String) As T Using ms = New MemoryStream(Encoding.Unicode.GetBytes(input)) Dim serilizer … Continue reading Serialize Your Objects to and from JSON

Why I LOVE VB.NET!

I recently started a new job that uses C#. I have been trying for two frickin hours to get Trace Listeners working in an application here with no luck at all. So to test that I have the web.config setup correctly, I added the following:var log = new Microsoft.VisualBasic.Logging.Log();log.WriteEntry("VB Log"); Bam, it works! Dang I … Continue reading Why I LOVE VB.NET!

dotNetTips.com Utility Release 1

Today I released the first public version of my dotNetTips.com Utility assembly. This is an open source .NET 2.0 utility assembly that contains useful common code that anyone can use in just about any project. Helper classes include Active Directory, Validation, IIS, File IO, Security, Computer Info, Web, XML and more. Other classes include a better … Continue reading dotNetTips.com Utility Release 1

Checking Permissions Before Accessing A File

Often, it's a good idea to make sure the user trying to access the file has permissions to it before performing an operation like read, write or delete. Below is code that makes this pretty easy.   Sub DemandFileReadPermission(ByVal fileName As String)     If System.IO.File.Exists(fileName) Then       Dim filePermission As New System.Security.Permissions.FileIOPermission(System.Security.Permissions.FileIOPermissionAccess.Read, System.Security.AccessControl.AccessControlActions.View, fileName)       … Continue reading Checking Permissions Before Accessing A File

Convert Bitmap To Byte Array

If you need to convert a Bitmap to a Byte array, here is how you do it.   Public Shared Function ConvertToByteArray(ByVal value As Bitmap) As Byte()       Dim bitmapBytes As Byte()         Using stream As New System.IO.MemoryStream           value.Save(stream, value.RawFormat)         bitmapBytes … Continue reading Convert Bitmap To Byte Array

Convert An Array To A Delimited String

There are many times when I need to convert an array to a delimited string. Here is an easy way to do it using generics in .NET 2.0.   Public Shared Function ConvertArrayToString(Of arrayType As {IEnumerable})(ByVal array As arrayType(), ByVal separator As Char) As String         If Not IsValidArray(array) Then     … Continue reading Convert An Array To A Delimited String

Finding A Drives Serial Number

.NET still does not expose the drive serial number via the framework. For that you will need to use WMI. Here is the code. Shared Function GetDriveSerialNumber(ByVal drive As String) As String     Dim driveSerial As String = String.Empty       'No matter what is sent in, get just the drive letter   … Continue reading Finding A Drives Serial Number

Verify That An Array Is Valid

Here is some simple code to validate that an array is valid. Before trying to use an array, you should always validate it with this code first.   Public Shared Function IsValidArray(ByVal array As Array) As Boolean       Dim valid As Boolean = False         If array Is Nothing Then … Continue reading Verify That An Array Is Valid