Thursday, May 7, 2009

Thursday, February 19, 2009

Converting file length into User friendly format (GB, MB, KB, Bytes)

Use following function to convert file length in bytes to user friendly format


private string FormatByteSize(long length)
{
const int KB = 1024;
const int MB = 1024 * KB;
const int GB = 1024 * MB;
if (length > GB)
{
return (length / GB).ToString("0.00") + " GB";
}
else if (length > MB)
{
return (length / MB).ToString("0.00") + " MB";
}
else if (length > KB)
{
return (length / KB).ToString("0.00") + " KB";
}
return length.ToString()+" Bytes";
}

Thursday, February 12, 2009

Silverlight Calculator

Calculator built using silverlight


Source Code can be found here

Silverlight Error handling at user control level

When you are developing user control in Silverlight you might want to handle all errors for that user control at one place. For handling all errors at one place you have to subscribe to event
UnhandledException of the App class
Code
  public partial class Page : UserControl
{

public Page()

{

InitializeComponent();

App.Current.UnhandledException += new EventHandler(Current_UnhandledException);



}



void Current_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)

{

//handle exception here. like showing a message box

}



}


Tuesday, January 20, 2009

RAM vs ROM

A good article explaining difference between RAM & ROM http://blogs.msdn.com/windowsmobile/archive/2005/08/19/453784.aspx

Main differences are (taken from article)
RAM: very fast, but burns a lot of power.
ROM: much slower, but burns very little power.
Importantly, RAM needs a constant supply of power for it to remember its data. ROM doesn't. In other words, if your batteries die, you'll lose the stuff in RAM, but the stuff in ROM will still be there.

Monday, December 22, 2008

Write C Program using Visual Studio .net

Please see below link to write a Hello World application in C using visual studio
http://support.microsoft.com/kb/829488

Friday, October 31, 2008

Force a website to use WWW using IIS

Some times you need to redirect all request to http://example.com/ to http://www.example.com/ . To achieve this you can write code to see if request is for http://example.com/ and redirect to http://www.example.com/ . We can also achieve this using just IIS (i think it will be faster than Code base solution) taking advantage of host headers. Add hostheader http://www.example.com/ to your website (see how to this in this link http://www.visualwin.com/host-header/ ) . Now create another new website with exact same settings as your first website exept host header value it should be example.com. Now right click your new website in IIS select properites and goto Home directory tab. select "A redirection to URL" radio button, in the "Redirect to" text box enter http://www.example.com/ . See the screen shot below for more details