Wednesday, November 11, 2009

Get the User's Temporary Directory in .NET

System.IO.Path.GetTempPath()

or

Environment.GetEnvironmentVariable("temp")

Tuesday, October 27, 2009

How to find Regasm.exe and use it in a .Bat file

I need to use RegAsm.exe to register several assemblies in a .bat file; however, since RegAsm.exe is not in the system path, it is difficult to just use like Regsvr32 which is always in the system path. I suppose the reason for this is that there can be multiple .NET Frameworks installed and you need to use the correct one.

You can use the WINDIR enviroment variable to get the root of the path. It will probably be something like:

C:\WINDOWS

You then need to add "\Microsft.NET\Framework\" to the path, and finally the path to the specific .NET Framework you are using:

SET fwpath="%windir%\Microsoft.NET\Framework\v2.0.50727"

%fwpath%\regasm.exe app.dll

How to pass TARGETDIR with CustomActionData and not get an Error

Maybe it is just me, but it seems like everything I need to do with an MSI setup is never as easy as it should be. Here is just an other example.

I need to pass the Target Directory for the installation to the InstallClass that I am using in the MSI Custom Actions (I have to do this because of other things in the MSI that don't work like they should). However, when I define the CustomActionData as:

/targetPath=[TARGETDIR]

or

/targetPath="[TARGETDIR]"


I get the following error:

Error 1001. Exception occurred while initializing the Installation:System.IO.FileNotFoundException


The solution I have found is to say this:

/targetPath="[TARGETDIR]\"

I found this info from the following post:

http://www.dotnet247.com/247reference/msgs/35/179584.aspx


I later found the Microsoft documentation on solving the problem:

http://msdn.microsoft.com/en-us/library/2w2fhwzz(VS.71).aspx

Thursday, October 22, 2009

Import an Excel File with VB.NET

Here is a simple solution for importing an Excel file into VB.NET using an OleDbConnection:

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_CSharp/Q_22487951.html

Wednesday, September 16, 2009

Some Good Examples of MemoryStream in C#

Here are several good examples of using MemoryStream in C#:

http://www.java2s.com/Code/CSharp/File-Stream/CreateaMemoryStream.htm

Formatting DateTime in C#

Here is an excellent list of the C# Formatting specifications for the DateTime type. The VB.NET formatting could easily be derived from this post as well:

http://www.csharp-examples.net/string-format-datetime/

Monday, September 14, 2009

How to Save a Bitmap as a 1BPP (bitonal) TIFF File in .NET

If you try to use the EncoderValue.CompressionCCITT4 value to save a Bitmap out as a 1 BPP Tiff file, you will get an error "Invalid Parameter Value". It turns out that .NET can't go from an RGB to a Bitonal image with the Save method on a Bitmap (no matter how you set the encoder parameters). The following posting by Michael McCloskey solves the problem:

http://www.codeproject.com/KB/GDI-plus/BitonalImageConverter.aspx?msg=2020403


Easy to use and runs quickly.