Monday, December 6, 2010

Formatting Dates (UK, USA)

CDATE does *NOT* return *any* date format!

CDATE *accepts* a date in the current settings.

FormatDateTime will *format* per the current settings.
Or just converting any date to a string via Response.Write or CSTR( ) will do so.

BUT...But that is *not* necessarily the "Regional Settings" on your machine! It is the settings *of the Web Server* that matter.

And to change that, you use
Session.LCID = &H0409 ' for USA
Session.LCID = &H0809 ' for U.K.
To see other LCIDs (and there are dozens!), do this:
(1) Google em!

How to register a C# or VB.Net DLL

Regasm.exe is an Assembly Registration tool used to read the metadata within an assembly. It also adds the necessary entries to the registry allowing a COM client (VB6 applications, or Microsoft VBA, eg. Access, Excel, etc) to create .NET Framework classes. Once a class is registered using Regasm.exe, a COM client can use it as a COM component.

RegAsm.exe file comes with .Net framework installation and can be found in Microsoft.NET framework folder. There are different versions of RegAsm.exe.

1..Net framework 2.0, 3.0, and 3.5 use the same RegAsm.exe which locates in the .Net framework V2.0 folder.
C:\WINNT\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe
Or
C:\Windows\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe
2..Net framework 4.0 uses a new RegAsm.exe which locates in the .Net framework V4.0 folder.
C:\WINNT\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe
Or
C:\Windows\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe
RegAsm.exe and DLL mapping
If you receive this error "RegAsm : error RA0000 : Failed to load 'c:\winnt\system32\YourDLLFile.dll' because it is not a valid .NET assembly", you are probably trying to use a .Net framework 2 RegAsm.exe to register a DLL that is created by using .Net framework 4.

.Net Framework RegAsm.exe default installation path Your DLL should be created by
.Net framework 2.0/3.0/3.5 C:\WINNT\Microsoft.NET\Framework\v2.0.50727\RegAsm.exe .Net framework 2.0/3.0/3.5
.Net framework 4.0 C:\WINNT\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe .Net framework 4.0

So when registering DLL assemblies that are created by .Net framework 4, we must NOT use RegAsm.exe that comes in .Net framework 2.0/3.0/3.5 folder.

How to run RegAsm.exe ?
To execute RegAsm.exe, open a command prompt window, and navigate to the folder where RegAsm.exe is located and run it (otherwise you will get "RegAsm is not recognized as internal or external command, operable program or batch file" error message).

Assume I have already added my DLL to folder C:\WINNT\system32 then I can run the following command:

C:\WINNT\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe SimpleCalc.dll /codebase

Note that you don't need to specify C:\WINNT\system32 in the command as it's a system folder. RegAsm.exe will automatically look up SimpleCalc.dll in C:\WINNT\system32 directory.

The /codebase parameter is an optional parameter that adds information about the DLL to the Windows registry which specifies the assembly's path on the disk.

Regasm can also be used to unregister a DLL.

If the DLL you got does not have type library file associated with it, one can be generated by using the Regasm utility and the /tlb option.

C:\WINNT\Microsoft.NET\Framework\v4.0.30319\RegAsm.exe SimpleCalc.dll /tlb:SimpleCalc.tlb

Note that, to export a type library from the DLL, you need administrator privileges on the computer, or you will receive this type of error "RegAsm : error RA0000 : An error occurred while saving the exported type library: Access is denied..." because the account under which you run regasm.exe doesn't have rights to write to the folder.

Note that you can create environmental variables for the .Net framework RegAsm.exe to simplify DLL registration.