Eject and Pop-in your CD / DVD with a hotkey Jun 13, 2009 UTILS

If you are annoyed with the malfunctioning of your CD/DVD ROM. This small utility will help you to eject and and again pop-in inside the ROM. Just press CTRL + Q to toggle. Place it anywhere you like on your system, I recommend to create a folder and then place a this utility inside it as it will installs on the first time you run the application and start-up with your windows the next time you boot in.

Download Link: CDAX.zip (113.18 kb)

Shoutdown/Logoff/Hibernate/Stand By - Use CODE to do 'em all Jun 12, 2009 C#   CODE SNIPPETS

Step 1: Add the following line to use the namespace. This is necessary as we need to use the User32.dll with DLLImport attribute.

using System.Runtime.InteropServices;

Step 2: Now add the below line to your code to use the methods from the User32.dll.

public static extern void LockWorkStation();
public static extern int ExitWindowsEx(int uFlags, int dwReason);

Step 3: Once you complete the above two steps, you can now call the methods on button click or after some or with some particular event or the way you like.

LockWorkStation(); //Locks the workstation, Equivalent to WIN+L
ExitWindowsEx(0, 0)//Shutdowns the machine 
Application.SetSuspendState(PowerState.Suspend, true, true)  //Put the machine in stand-by mode
Application.SetSuspendState(PowerState.Hibernate, true, true); // Hibernates the system
Convert ASCII values from hex to characters May 30, 2009 C#   CODE SNIPPETS

This C# code takes in a list of ASCII values (hexadecimal) and shows the actual characters behind, thus converting hex values to strings.

// An object storing the hex value
string HexValue = "4765656B7065646961";
// An object storing the string value
string StrValue = "";
// While there's still something to convert in the hex string
while (HexValue.Length > 0)
    // Use ToChar() to convert each ASCII value (two hex digits) to the actual character
    StrValue += Convert.ToChar(Convert.ToUInt32(HexValue.Substring(0, 2), 16)).ToString();
    // Remove from the hex object the converted value
    HexValue = HexValue.Substring(2, HexValue.Length - 2);
// Show the converted value
Printing word documents without showing Print Dialog May 29, 2009 C#

Just one Click! and documents queued to the printer. The code will provide you the full flexiblity to set the default printer and also to set other word document settings. I used the code to convert the word document to PDF using Adobe PDF printer driver, as I was unable to get the code to convert the word files to PDF using DLLs.Cool

Download the code and don’t forget to look at the comments.

Download: docprntpdf.zip (645.83 kb)

Populating, Restore and Backup SQL Database using C# May 27, 2009 C#

You want to add a functionality in your C# application to allow user to select the database to restore and taking backups of the database. C# provides the classes to allow a programmer to achieve this in the application.

Before you go and implement this feature in your application, make sure you have added the references of the following namespaces:

  1. Microsoft.SqlServer.Smo
  2. Microsoft.SqlServer.ConnectionInfo

Click the below link to download the full application.

Download: DBBackup.zip (290.99 kb)