Posts

Showing posts from December, 2015

Add url to google

Image
For adding url click on below link Add url to google After completing this process with 2-3 days Google verify your url and based on your SEO it will ranks your site.  After applying ranking it will add your url to its database

Email sending in C#

Email sending with Attachment public static bool SendEmailMessage( string SenderEmailAddress, string SenderPassword, string SenderHostName, int SenderPort, string Subject, string Body, string emailTO, bool EnableSSL = false, string CC = "", string BCC = "", MailPriority Priority = MailPriority .Normal, string path = "") {             try             {                 System.Net.Mail.MailMessage objMail = new System.Net.Mail.MailMessage();                 //Set from address                 objMail.From = new MailAddress(SenderEmailAddress);                  // Set to addresses                 if (string.IsNullOrEmpty(emailTO))                 {                     objMail.To.Add(new MailAddress(emailTO));                 }                 // Set CC addresses                 if (string.IsNullOrEmpty(CC))                 {                     objMail.CC.Add(new MailAddress(CC));                 }                  // Set BCC addresses

Export GridView to CSV/Excel in C#

Step 1 : Bind GridView             //This allows you to bind all data of GridView into ExcelSheet             GridView1.AllowPaging = false;             GridView1.DataSource = //List Object or DataTable             GridView1.DataBind();   Step 2 : Export GridView To Excel              HttpContext .Current.Response.ClearContent();             HttpContext .Current.Response.AddHeader("content-disposition", "attachment; filename="                           + fileName + ".xls");   // fileNmae = Name of file             HttpContext .Current.Response.ContentType = "application/excel";             System.IO.StringWriter sw = new System.IO.StringWriter ();             HtmlTextWriter htw = new HtmlTextWriter (sw);             GridView1.RenderControl(htw);             HttpContext .Current.Response.Write(sw.ToString());             HttpContext .Current.Response.End();  

Create DataTable from List in C#

T is type of Class which you want convert i.e. T = Class Name  public static DataTable ConvertToDataTable<T> (List <T> data)  {             //Create property description collection object of you table type object             PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(T));             DataTable table = new DataTable();            //Bind object field as header row of DataTable             foreach (PropertyDescriptor prop in properties)             {                 table.Columns.Add(prop.Name, typeof(string));             }             //Bind data of list into DataTable             foreach (T item in data)             {                 //Create dataRow object for Table                 DataRow row = table.NewRow();                 foreach (PropertyDescriptor prop in properties)                 {                    //Assign list value into dataTable column                     row[prop.Name] = pro

Image cropping in C#

public static byte [] CropImage( string Img, int Width, int Height, int X, int Y) {             try             {                 //Generate Image from specified Image file path                 //Img = file path                 System.Drawing.Image OriginalImage = System.Drawing.Image.FromFile(Img);                 //Generate Bitmap with given Width and Height                 Bitmap bmp = new Bitmap(Width, Height);                //Set Resolution of Bitmap                 bmp.SetResolution(OriginalImage.HorizontalResolution, OriginalImage.VerticalResolution);                 //Create Graphic for Bitmap                 Graphics Graphic = Graphics.FromImage(bmp);                 Graphic.SmoothingMode = SmoothingMode.AntiAlias;                 Graphic.InterpolationMode = InterpolationMode.HighQualityBicubic;                 Graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;                 //Draw image from Original image for above Graphic Object             

Convert Number into text format in C#

Below function will convert inputted number into text format public static string NumberToText( int number, bool isUK) {             // return "Zero" if number is 0             if (number == 0) return "Zero";                        string and = isUK ? "and " : ""; // deals with UK or US numbering               if (number == -2147483648) return "Minus Two Billion One Hundred " + and +             "Forty Seven Million Four Hundred " + and + "Eighty Three Thousand " +             "Six Hundred " + and + "Forty Eight";             int[] num = new int[4];             int first = 0;             int u, h, t;             System.Text.StringBuilder sb = new System.Text.StringBuilder();             if (number < 0)             {                 sb.Append("Minus ");                 number = -number;             }             string[] words0 = { "", "One ", &qu

Check string is number or not in C#

Int.TryParse() method converts string into integer and if this conversion is not possible then it will return false means your inputted string is not number string number = "1234"; int a = 0; bool isNumber = int.TryParse(number, out a); if (isNumber == true) {             //string is valid number } else {            //Given string is not a number }