Posts

Post_Method and Get_Method from C#

  public static string Post_Method(string uri, string command)     {         WebRequest req = null;         WebResponse rsp = null;         string tempReply = "";         try         {             req = WebRequest.Create(uri);             req.Method = "post";             req.ContentType = "application/x-www-form-urlencoded";             StreamWriter writer = new StreamWriter(req.GetRequestStream());             writer.Write(command);             writer.Close();             // Send the data to the webserver             rsp = req.GetResponse();             StreamReader reader = new StreamReade...

Get DataKeyName value on rowcommand and rowdatabound event in asp.net

Simplest way to get Datakeyname Value  on rowcommand and rowdatabound event in asp.net < asp : GridView ID ="Grd" runat ="server   DataKeyNames ="rowid , Status , Sender , sscalltime"                                                 onrowcommand ="GridINfo_RowCommand"   onrowdatabound ="GridINfo_RowDataBound">                                             < Columns > < asp : TemplateField ItemStyle-Width ="120px" >               ...

Create PDF from HTML in asp.net

This is a simple article to generate pdf from html string. Just call the below code snippet .Here i am using  NReco.PdfGenerator.dll to generate pdf.  NmaeSpace using System.Text; using System.IO; using NReco; protected void Button4_Click( object sender, EventArgs e)     {         string PdfPath= "Pdf" + new Random ().Next().ToString();         var htmlContent = String .Format("Hello Test <b>PDF</b>" );  // html string come here         var htmlToPdf = new NReco.PdfGenerator. HtmlToPdfConverter ();         var pdfBytes = htmlToPdf.GeneratePdf(htmlContent);         FileStream file = File .Create(Server.MapPath( "~/PDF/" +PdfPath+ ".pdf" ));         file.Write(pdfBytes, 0, pdfBytes.Len...

Login with facebook in asp.net using C#

Name Space using System.Configuration; using System.Data.SqlClient; using System.Data; using Newtonsoft; using Newtonsoft.Json; using Newtonsoft.Json.Linq;     string appid = "" ;    string secretid = "" ;  // here replace " /Fb/Login.aspx"  with your redirect url page protected void Page_Load( object sender, EventArgs e)     {    HyperLink1.NavigateUrl = "https://www.facebook.com/v2.4/dialog/oauth/?client_id=" + appid + "&redirect_uri=http://" + Request.ServerVariables[ "SERVER_NAME" ] + ":" + Request.ServerVariables[ "SERVER_PORT" ] + "/Fb/Login.aspx&response_type=code&state=1" ;               if (Request.QueryString[ "code" ] != "" )         {             GetFacebookUserData(Request.QueryString[ "code" ]);  ...

SQL Optimization Techniques

SQL  Optimization Techniques: 1)  The sql query becomes faster if you use the actual columns names in SELECT statement instead of than '*'. For Example:  Write the query as SELECT id, first_name, last_name, age, subject FROM student_details; Instead of: SELECT * FROM student_details; 2)  HAVING clause is used to filter the rows after all the rows are selected. It is just like a filter. Do not use HAVING clause for any other purposes.  For Example:  Write the query as SELECT subject, count(subject)  FROM student_details  WHERE subject != 'Science'  AND subject != 'Maths'  GROUP BY subject; Instead of: SELECT subject, count(subject)  FROM student_details  GROUP BY subject  HAVING subject!= 'Vancouver' AND subject!= 'Toronto'; 3)  Sometimes you may have more than one subqueries in your main query. Try to minimize the number of subquery block in your query.  For Example:  Write the quer...

Create Web Request in C# using asp.net

Name Space  using System.Collections.Specialized; using System.Net; using System.IO;  public string Post_Method(string uri, string command)     {         WebRequest req = null;         WebResponse rsp = null;         string tempReply = "";         try         {             req = WebRequest.Create(uri);             req.Method = "post";             req.ContentType = "application/x-www-form-urlencoded";             StreamWriter writer = new StreamWriter(req.GetRequestStream());             writer.Write(command);             writer.Close();             // Send the data to the webserver             rsp = req.GetR...

Export Html string to word in asp.net

This is a simple blog to demonstrate how to export hmtl string to MS Word. So here i going to create a function with parameter filename and htmlstring. public void downloadAsWord(String filename, String htmlstring)     {         HttpContext.Current.Response.Clear();         HttpContext.Current.Response.ContentType = "application/msword";         HttpContext.Current.Response.ContentEncoding = System.Text.UnicodeEncoding.UTF8;         HttpContext.Current.Response.Charset = "UTF-8";         Response.AddHeader("Content-Disposition", "attachment; filename=" + filename + ".doc");         Response.Write("<html>");         Response.Write("<head>");         Response.Write("<META HTTP-EQUIV=Content-Type CONTENT=text/html charset=UTF-8>");         Response.Write("...