C#

Firefox Sessionstore backup program

  1. /*
  2.  *  I love Firefox,  I love Tabs.  But sometimes these two don't
  3.  *  get along.

Solving COMException / Unknown error (0x80005000)

Got this funny little thing today when I was trying to enumerate children of a Directory Entry:.

Visual Studio : Detect in code if program is run in debug or release

Here's a useful bit of information.  If you need to know if you are running your program in debug mode or not you can do this :

#if DEBUG
  // Program is running in debug mode
#endif

Here's an example of why this is useful.  Say you are creating a Windows Service and we all know how boring and time consuming it can be to install the service, test it, make modifications or fixes and then test it all again, not to mention you can't debug it properly. If you put this in the main class file

C# : Change Folder Quota Programmatically in Windows 2008 R2

  1. // Here is an example on how you can interface with FSRM (File Server Resource Manager) to programmatically set or change a quota for a given directory.
  2. // First you need to find and reference the srmlib.dll file from either the Windows SDK 7.1 or from Windows 2008 R2 installation.
  3.  
  4. // you need these using statements.
  5. using Microsoft.Storage;
  6. using System.Runtime.InteropServices;
  7. using System.IO; // For the Directory creation if needed
  8.  
  9. // Here comes the code that goes into your main class or wherever you need it.
  10.  
  11. // Directory to Set/Change the quota of
  12. string directory = @"c:\Lim

Convert Decimal submask into CIDR in C#

  1. // Here's another function that does the reverse of the other one (CIDR 2 Decimal)
  2. // It's a bit longer since it's more complicated to convert the decimal value back into CIDR and make sure it's in the correct format
  3.  
  4. public int DECIMAL2CIDR(string decim)
  5. {
  6.   int cidr = 0;
  7.   string[] proof = decim.Split('.');
  8.   bool lessthan255 = false;
  9.  
  10.   // We expect the string to be in the form of z.x.y.w , if there are more or less than 3 dots in there then something is wrong
  11.   if (proof.Length != 4)
  12.   {
  13.     throw new Exception("Input must be in the form z.x.y.w");
  14.   }
  15.  
  16.   // Loop through e

Convert CIDR to Decimal Submask in C#

  1. // If you're looking for information about how CIDR works I recommend the wikipedia articles :
  2. // - http://en.wikipedia.org/wiki/Subnetwork
  3. // - http://en.wikipedia.org/wiki/CIDR_notation
  4. // - http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
  5.  
  6. // This function takes in the CIDR address (/x notation) and returns it in a decimal notation (a.b.c.d)
  7.  
  8. public string CIDR2DECIMAL(int cidr)
  9. {
  10.   string[] decim = new string[4];
  11.   // We go through each octagon in the decimal address
  12.   for (int i = 0; i < 4; i++)
  13.   {
  14.     if (cidr > 8)
  15.     {
  16.       decim[i] = "255";
  17.       cidr -=

C# : Enumerate Event Handlers in Windows Media Services

  1. // This code sample enumerates all available event handlers
  2.  
  3. // Example output :
  4. /*
  5. 7 event handlers available
  6.  
  7. WMS Client Logging
  8. CLSID : {09EE74B0-961A-11D2-AEDE-0060089BBAF4}
  9. Enabled : True
  10. Status : 14
  11. Properties
  12.         WMSSystemPlugin : 1
  13.         ASPMoniker : LoggingAdmin.asp
  14.         UnsupportedLoadTypes : 2
  15.         MMCMoniker : CLSID:{9C046A5B-3EC3-11D3-B38A-00C04F610D6B},CLSID:{26C1EDA6-4C44-46DE-84BE-901064C754EB},CLSID:{9E531984-0384-4b25-9DFB-E804165D1D75}
  16.         SubCategory : Logging
  17.         Name : WMS Client Logging
  18.         Description : Enables you to log activit

A (very) simple way to validate a checkbox in asp.net

  1. // Since asp/asp.net doesn't have a form validator to check checkboxes we need to use a custom validator.
  2. // So here's a very simple and crude way to achieve this
  3.  
  4. // The 4 Guys From Rolla have an article on a more comprehensive way to do this,  but if you don't mind quick and dirty continue reading.

List all publishing points on a WMS 9.5 instance

  1. // ------------------------
  2. // This requires the following using statement
  3. //
  4. // Note that this is not present by default in Visual Studio,  you require either an installed WMS Server on the local machine or copy and reference the Microsoft.WindowsMediaServices.dll file from either the Windows SDK or a WMS Server
  5. using Microsoft.WindowsMediaServices.Interop;
  6. // ------------------------
  7.  
  8. // This lists all publishing points present on the local Windows Media Services 9.5 instance (WMS in Windows 2008), this will probably work on older WMS Servers as well.
  9.  
  10. // Example output is :
  11. /*
  12.  *

Unix Timestamp in C#

  1. // The Unix Timestamp is the number of seconds since the Unix Epoch began,
  2. //   ( The Unix Epoch is January 1. 1970 00:00 UTC/GMT )
  3. // So all that is needed is to calculate the number of seconds since,
  4.  
  5. // This shows you how to get the Unix time using a simple simple TimeSpan.
Syndicate content