Skip to main content

Posts

Showing posts from 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.............................................................................................************ ...

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)         {             retur...

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.Ev...

How can I get a enum value

int value = (int)Enum.Parse(typeof(CategoriesType), Enum.GetName(typeof(CategoriesType), CategoriesType.Operations));   public enum CategoriesType : int     {         Operations = 1001,         Personnel = 1002,         Safety = 1003     }

Regular Expressions for URL Rewriting

A complete guide to regular expressions is rather beyond the scope of this article. However, important points to remember are that the entire pattern is treated as a regular expression, so always be careful of characters that are “special” characters in regular expressions such as .(DOT stands for any character). . (any character) * (zero of more of the preceding) + (one or more of the preceding) {} (minimum to maximum quantifier) ? (ungreedy modifier) ! (at start of string means “negative pattern”) ^ (start of string, or “negative” if at the start of a range) $ (end of string) [] (match any of contents) - (range if used between square brackets) () (group, backreferenced group) | (alternative, or) \ (the escape character itself) Flags Flags are added to the end of a rewrite rule to tell Apache how to interpret and handle the rule. They are comma-separated, and contained in square brackets. Here’s a list of the flags, with their meanings C (chained with next ...

Upload CSV File And Read Using ASP.NET

--------------------------------------------------------------- CSVReader.cs --------------------------------------------------------------- using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO; using System.Text; using System.Collections; public class CSVReader {     //     private Stream objStream;     private StreamReader objReader;     //add name space System.IO.Stream     public CSVReader(Stream filestream) : this(filestream, null) { }     public CSVReader(Stream filestream, Encoding enc)     {         this.objStream = filestream;         //check the Pass Stream whether it is readable or not    ...

The Ten Most Asked SQL Server Questions And Their Answers

If you are active in the SQL Server newsgroups and forums as I am, you will notice that the same questions keep popping up all the time. I picked ten of them which I see daily. Since this became a pretty long blogpost I have linked all the questions below to jump to the question itself. 1) Selecting all the values from a table for a particular date 2) Search all columns in all the tables in a database for a specific value 3) Splitting string values 4) Select all rows from one table that don't exist in another table 5) Getting all rows from one table and only the latest from the child table 6) Getting all characters until a specific character 7) Return all rows with NULL values in a column 8) Row values to column (PIVOT) 9) Pad or remove leading zeroes from numbers 10) Concatenate Values From Multiple Rows Into One Column 1 Selecting all the values from a table for a particular date This is a very popular question and people sometimes answer that you need ...