Showing posts with label Productivity. Show all posts
Showing posts with label Productivity. Show all posts

Monday, May 21, 2012

XmlSerializationHelper

This is one of those helper classes that I keep using very often.

using System.IO;
using System.Text;
using System.Xml.Serialization;

public class XmlSerializationHelper<T> where T : class
    {
        public string Serialize(T objectToSerialize)
        {
            var sb = new StringBuilder();
            var serializer = new XmlSerializer(typeof(T));
            using (var writer = new StringWriter(sb))
            {
                serializer.Serialize(writer, objectToSerialize);
            }
            return sb.ToString();
        }

        public T Deserialize(string xml)
        {
            var serializer = new XmlSerializer(typeof(T));
            return (T)serializer.Deserialize(new StringReader(xml));
        }
    }

Usage:
string xml = new XmlSerializationHelper<SomeClass>().Serialize(obj);
AND
SomeClass obj = new XmlSerializationHelper<SomeClass>().Deserialize(xml);
Note: I am not using var here, just so that its clear what the return types are.

Wednesday, November 30, 2011

Monday, November 21, 2011

PDF Printer for Windows

Whenever I need to have a copy of something important, such as a travel ticket, I like to print to file instead of a regular printer. This way, I could always print it again without having to generate the material again. I used to use the Microsoft Office Document Image Writer for this. This is one of the non-default features that comes with Microsoft Office 2003 or 2007, but has been discontinued in Office 2010.
http://support.microsoft.com/kb/982760

So, when I have Office 2010 on my new PC, I install just this component from the Office 2007 installer, up until now. The MDI or TIF format works fine locally, but if I have to share it with someone else, it doesnt work as well.

For instance, when I booked a ticket for my father, I feel sending a PDF is a much better option. So, I googled for it, and the first paid ad brought this free PDF printer for Windows.
http://www.pdflite.com/printer?gclid=CPDAgNqyyawCFUwaQgodmHatrQ

Tried and tested, works fine.

Wednesday, November 16, 2011

Unread mails in Gmail

Once in while, I go to the Spam folder in my Gmailbox and retrieve the ones I do not consider spam. This pushes such emails to my inbox and then I see the nagging sign next to the Inbox that says 20 unread messages. Typically, I can find all of them on page 1. But since these are retrieved from the Spam folder, the dates would stretch to a few days earlier and so, I would have to navigate across pages to find each of these unread emails.

Gmail, fortunately, like Outlook and unlike most other web mail providers, gives a way to filter emails based on whether they are unread. To do this, simply search for label:unread while in Gmail, and you get this filtered list. Cool, huh?

Source: http://www.dailyblogtips.com/gmail-tip-how-to-browse-only-the-unread-messages/