Skip to main content

Posts

Showing posts from December, 2012

Resizing an Image without losing any quality

public static byte[] CreateThumbnail(byte[] imageBytes, int lnWidth, int lnHeight)     {         byte[] b;         System.Drawing.Bitmap bmpOut = null;         try         {             Bitmap loBMP = new Bitmap(System.Drawing.Image.FromStream(new MemoryStream(imageBytes)));             ImageFormat loFormat = loBMP.RawFormat;             decimal lnRatio;             int lnNewWidth = 0;             int lnNewHeight = 0;             if (loBMP.Width < lnWidth && loBMP.Height < lnHeight)             {                 //NEW.............................................................................................************                 var image = loBMP;                 using (MemoryStream ms = new MemoryStream())                 {                     image.Save(ms, ImageFormat.Bmp);                     return ms.ToArray();                 }                 //return loBMP;             }             if (loBMP.Width > loBMP.Height)          

Using jQuery to center a DIV on the screen

Create Function $.fn.center = function () {             this.css({                 'position': 'fixed',                 'left': '50%',                 'top': '50%'             });             this.css({                 'margin-left': -this.width() / 2 + 'px',                 'margin-top': -this.height() / 2 + 'px'             });             return this;         } ----------------------------------- Use this function $("#control_Id").center();

Conversion Algorithms

using System; using System.Collections.Generic; using System.Text; namespace ConversionAlgorithms {     class clsConversion     {         // Convert Degree to Radian         public static double DegreeToRadian(double degree)         {             return (Math.PI / 180) * degree;                     }         // Convert Radian To Degree         public static double RadianToDegree(double radian)         {                         return (180 / Math.PI) * radian;         }         // Round Float to Integer         public static int RoundFloatToInt(float f)         {             return ((int)Math.Round(f));                          // If you want to round to a fixed decimal place, say 3             // return ((int)Math.Round(f,3));         }         // Celcius to Fahrenheit         public static double CelsiusToFahrenheit(double cel)         {             return (((.9 / .5) * cel) + 32);         }         // Fahrenheit to Celcius         public static d

explain synchronous and asynchronous in C#

Usually the methods are synchronous. That means that you call them, they gets executed. And when they finish you get the control back. The asynchronous methods are different. You call them. They start executing, but return the control over the execution back to the thread which called them while they continue to execute in different thread. ------------------------------------------------------------- Synchronous is one after another, so you send one email when that process is done it sends the next one. Asynchronous starts sending an email and it doesn't care if the first one is done and will start the second, and this goes on until all emails are sent. Normally, an asynchronous process would open a new thread and run in the background.

Can I set an unlimited length for maxJsonLength in web.config?

The MaxJsonLength property cannot be unlimited, is an integer property that defaults to 102400 (100k). You can set the MaxJsonLength property on your web.config: <configuration> <system.web.extensions> <scripting> <webServices> <jsonSerialization maxJsonLength = "50000000" /> </webServices> </scripting> </system.web.extensions> </configuration>

Windows Service in C#

http://www.c-sharpcorner.com/uploadfile/mirfan00/windows-service-in-C-Sharp/ Introduction This article is about Windows Service in .Net Frame. We learn how to make and use windows service in our C#.Net Frame applications .     Steps to create windows service   1.  Open new windows project in Visual Studio. 2.  Right click on windows service screen and select add installer Two installers added and displays on windows service design view. 3.  Go to service installer property and sets the following properties Description Display Name Service Name Start Type    4.  Go to service process installer property and sets the account property to 'Local System'     5.  Now drag a tool of evenLog1 from tool box into service designer and write the following code:     public Service1() {    InitializeComponent();  if (!System.Diagnostics.EventLog.SourceExists("MySource"))     System.Diagnostics.EventLog.CreateEventSourc