Emil’s Blog

Programming Windows, .Net, EPiServer and whatnot…

[Powered by WordPress.]

November 30, 2008

Serialize object to Xml string

by @ 21:52. Filed under .Net programming

For easy reference, this is how to serialize an object to an Xml string:

public static string SerializeToXmlString<T>(T o)
{
   XmlSerializer serializer = new XmlSerializer(typeof(T));
   StringWriter writer = new StringWriter();
   serializer.Serialize(writer, o);
   writer.Close();
   return writer.GetStringBuilder().ToString();
}

/Emil

November 27, 2008

Windows hibernation problems – solved!

by @ 20:00. Filed under Windows tips

Do you use the hibernation feature of Windows? Ever had any problems with it? I suspect that the answers to these two questions generally are the same...

Firstly, if you're using Windows XP and have more than 2 GB of RAM, it doesn't work. Fortunately there's a fix. For more info, see here.

Secondly, you're likely to have run into a host of other problems. My experiences include:

All these are extremely irritating, of course. Fortunately I've found a solution to all my problems so far, namely a little known but excellent free tool called MCE Standby tool (MST) that helps you configure the hibernation options. If you have similar problems to mine, give it a go!

When you install the tool, it puts a small, green "power" icon in the system tray:

To configure the hibernation options, right-click the system tray icon, and the main window is displayed:

To fix my two last problems above, I changed Selected sleep state to "S3", restarted the computer (might be unnecessary) and then changed back to "S4". Voilá, problems gone.

If you have problems with the computer awakening immediately after hibernation then it might be a USB-connected device that's waking the computer up (a mouse, keyboard, remote control receiver, etc). To fix this, you can select which deviced should be allowed to wake the computer up and this is done in the Devices tab:

Deselect all devices you suspect to be causing problems, and no awakening should occur. For me it was my keyboard.

There are more options in the useful little tool, but these are the ones that helped me so far. Give it a try if you have similar problems!

/Emil

BTW, "MCE" in the tools name stands for "Media Center Edition" indicating that hibernation problems can often be related to media systems. And indeed, many of my problems started after I installed Media Portal. My advice concerning that system is of course to keep away from it...

November 12, 2008

Retrieving the computer domain namne

by @ 17:42. Filed under .Net programming

This is how to retrieve the full domain name of the current computer:

public static string GetFullComputerName()
{
  ManagementObject cs;
  using (cs = new ManagementObject("Win32_ComputerSystem.Name='" +
      Environment.MachineName + "'"))
  {
    cs.Get();
    return String.Format("{0}.{1}", Environment.MachineName, cs["domain"]);
  }
}

To make this work, you need a reference to System.Management.dll.

The result will be something like:

active99.i.activesolution.se

If anyone has a better approach, please leave a comment :-)

/Emil

[powered by WordPress.]

jour·nal n. A personal record of occurrences, experiences, and reflections kept on a regular basis; a diary.

Internal links:

Categories:

Search blog:

Archives:

November 2008
M T W T F S S
« Sep   Dec »
 12
3456789
10111213141516
17181920212223
24252627282930


View Emil Åström's profile on LinkedIn

General links:

I read:

Visitors

Recent Comments

Spam caught

Other:

Clicky Web Analytics

36 queries. 0.800 seconds