searchforsolutions

Just another WordPress.com site

Monthly Archives: July 2012

Tip : Exception designing


  • Use checked exceptions for recoverable conditions and runtime exceptions for programming errors:Runtime exceptions should be used only to indicate programming errors, such as precondition violations.
  • Use exceptions only for exceptional conditions:That is, do not use exceptions for control flow.
  • Avoid unnecessary use of checked exceptions: In other words, don’t use checked exceptions for conditions from which the caller could not possibly recover, or for which the only foreseeable response would be for the program to exit.
  • Throw exceptions appropriate to the abstraction:In other words, exceptions thrown by a method should be defined at an abstraction level consistent with what the method does, not necessarily with the low-level details of how it is implemented.

C# : Working with .cab (cabinet) files


.NET does not have any classes for creating cabinet files out-of-box, so today I had to look what else is available out there. There are a couple of solutions I found for creating a .cab file from the .NET code. The one that actually worked for me was a library developed by Microsoft(!) as part of their Windows Installer XML (WiX) toolset. This toolset is distributed with a bunch of dlls as part of its SDK. The library that allows to create cabinet files is called Microsoft.Deployment.Compression.Cab and located under <WIX_Installation_Folder>\SDK.

In your project you need to add a reference to the Microsoft.Deployment.Compression.Cab.dll and to Microsoft.Deployment.Compression.dll (located under the same folder and has some base classes for types defined in the Microsoft.Deployment.Compression.Cab).

After doing this you can add files to a cabinet file from .NET with just a couple of line of code:

using Microsoft.Deployment.Compression.Cab;

//create a instance of Microsoft.Deployment.Compression.Cab.CabInfo
//which provides file-based operations on the cabinet file
CabInfo cab = new CabInfo(@”C:\Cabinet1.cab”);

//create a list with files and add them to a cab file
List<string> filesToArchive = new List<string>() { @”C:\file1″, @”C:\file2″ };
cab.PackFiles(null, filesToArchive, null);

//add a folder (including subdirectories) to another cab file with a maximum compression level
cab = new CabInfo(@”C:\Cabinet2.cab”);
cab.Pack(@”C:\folder”, true, Microsoft.Deployment.Compression.CompressionLevel.Max, null);

//unpack a cab file into C:\Unpacked folder
cab.Unpack(@”C:\Unpacked”);

The library has an MSDN style help file located under <WIX_Installation_Folder>\doc\DTFAPI.chm.

Another dll that also comes with WiX toolset SDK is Microsoft.Deployment.Compression.Zip.dll that provides similar functionality for packing and unpacking zip files.

Ref: http://wix.sourceforge.net/

Free web site designer tool


If you have been looking for a free website designer tools. Here are a bunch of them

C# : Credentials management on windows 2008


I was looking at options to save credentials on Wnidows platform.The traditional way is registry or DB or filesystem.But then one has to keep an eye on security issues & other headaches that follow.

Then i saw this feature in W2K8 ,”Credentials Manager”. The API for it are in C/C++ , but i needed a solution in C#. So I triaged a bit & came across a solution for the same http://www.microsoft.com/indonesia/msdn/credmgmt.aspx .

Another one : http://www.developerfusion.com/code/4693/using-the-credential-management-api/

Enjoy!