Archive for the ‘VB’ Category

Compute hash of a file

Computing the hash value of a file is quite strait forward. I use the routine below. It opens the file, specifies the hash-algorithm to use and returns the hash of the file. If you rather use MD5 hashes, just change hashAlgorithm into MD5CryptoServiceProvider.
Public Function ComputeFileHash(ByVal fileName As String) As String

  Dim hashAlgorithm As New System.Security.Cryptography.SHA1CryptoServiceProvider()

  [...]

More »

Am I running as a 32 or 64-bit application?

Here’s an easy way to determine if a .NET application is running as either 32 or 64-bit  application.
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
  If IntPtr.Size = 8 Then
    Response.Write("64-bit")
  ElseIf IntPtr.Size = 4 Then
    Response.Write("32-bit")
  End If
End Sub
C#
protected void Page_Load(object sender, EventArgs e)
{
  if (IntPtr.Size == 8)
  {
    [...]

More »

HttpContext.Current.Request.UserHostAddress returns ::1

One would expect HttpContext.Current.Request.UserHostAddress to return the IP address of the client computer. On my developement machine this would be 127.0.0.1. The application I’m working on acts on this IP address, so it is fital to get the correct address.
Since I’ve moved to Windows Server 2008 x64 on my laptop, I got ::1 as a result [...]

More »

MultipleActiveResultSets (MARS), SQL server 2000 and LINQ

Using the MultipleActiveResultSets setting in a connection string allows one to have multiple datareaders open on the same connection, at the same time. This setting was introduced with SQL server 2005. Setting it with SQL server 2000 does not have any effect, or so I thought.

More »

Could not load file or assembly ‘Name’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

On a 64-bit Windows installation this is caused by the fact that assemblies are compiled for x86 processors only. To change the compile settings do the following:

Open the project properties
Open the Compile tab
Open the Advanced Compile Options… window
Change the Target CPU from x86 to AnyCPU
Recompile

Happy programming!

More »

return confirm() doesn’t work as expected inside UpdatePanel

When using a GridView with a ButtonField for deleting records, setting a return confirm(‘Are you sure?’) on the onclick event doesn’t prevent the event from firing to the server.My first try was with this code:
<asp :ButtonField ButtonType="Image" ImageUrl="/images/b_drop.png" CommandName="DeleteRow" />

More »

Method error 12030 when using CascadingDropDown

I followed the example about using CascadingDropDowns linked to a databse as described on http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Walkthrough/CCDWithDB.aspx
Unfortunatly, the code contains a little bug, resulting a Method error 12030 or Method error 12031 being displayed in the dropdownlist, instead of the expected data. Because the webservice is being called from (java)script, using ASP.NET AJAX, the enclosing class has [...]

More »

Ini file reader (vb)

Here is a small class I use to read ini files.
Each setting in the ini file should be placed on a single line, using KEY = VALUE syntax.
Any line preceded with a # will be ingored as comment.
Imports System.IO

Public Class Ini

Private _items As New Hashtable
Private _filename As [...]

More »