Wednesday, 8 November 2017

Generate QR code in asp.net



               Follow Me To get Health tip and bodybuilding
instagram:sayyedtanveer1410




To generate QR Code in asp.net VB lang.

On Default.aspx page just put IMG tag.

 <img  id="img" alt="Alternate Text" />


On Default.aspx.vb 

Just Import MessagingToolkit.QRCode.Codec in namespace

 Dim data As String = "codens.blogspot.com"


  •              Dim qrCodeEncoder As New QRCodeEncoder()
  •             qrCodeEncoder.QRCodeBackgroundColor = Color.White
  •             qrCodeEncoder.QRCodeForegroundColor = Color.Black
  •             qrCodeEncoder.QRCodeEncodeMode = qrCodeEncoder.ENCODE_MODE.[BYTE]

  •             Dim scale As Integer = Convert.ToInt16(1) 'Here we need to give size of Qr
  •             qrCodeEncoder.QRCodeScale = scale
  •             Dim version As Integer = Convert.ToInt16(0)

  •             qrCodeEncoder.QRCodeVersion = version
  •             qrCodeEncoder.QRCodeErrorCorrect = qrCodeEncoder.ERROR_CORRECTION.H

  •             QRImageName = "Qr_IMG.Gif"
  •  qrImagePath = System.Web.HttpContext.Current.Server.MapPath("~\" & ConfigurationManager.AppSettings("ImageFolder").ToString & "\ImagesNew\")


  •             Try
  •                 If File.Exists(qrImagePath) Then
  •                     File.Delete(qrImagePath)
  •                 End If
  •             Catch generatedExceptionName As Exception
  •                 Throw
  •             End Try
  •             
  •             Dim bimg As Bitmap = qrCodeEncoder.Encode(data)
  •             bimg.Save(qrImagePath, System.Drawing.Imaging.ImageFormat.Gif)




Tuesday, 7 November 2017

How to convert linq query result in datatable


                         Follow Me To get Health and bodybuilding tip's
instagram:sayyedtanveer1410



LINQ stands for Language Integrated Query is a set of features introduced in Visual Studio 2008, using LINQ you can manipulate the data as similar SQL queries .Let us learn it practically how to convert LINQ query result to Datatable by creating one simple function.


Create function to named LINQResultQueryToDataTable which convert LINQ Result To DataTable as

public DataTable LINQResultQueryToDataTable<T>(IEnumerable<T> Linqlist) 
       { 
          
  1. DataTable dt = new DataTable();  
  2.   
  3.              
  4.             PropertyInfo[] columns = null;  
  5.   
  6.             if (Linqlist == nullreturn dt;  
  7.   
  8.             foreach (T Record in Linqlist)  
  9.             {  
  10.                   
  11.                 if (columns == null)  
  12.                 {  
  13.                     columns = ((Type)Record.GetType()).GetProperties();  
  14.                     foreach (PropertyInfo GetProperty in columns)  
  15.                     {  
  16.                         Type colType = GetProperty.PropertyType;  
  17.                              if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()  
  18.                         == typeof(Nullable<>)))  
  19.                         {  
  20.                             colType = colType.GetGenericArguments()[0];  
  21.                         }  
  22.   
  23.                         dt.Columns.Add(new DataColumn(GetProperty.Name, colType));  
  24.                     }  
  25.                 }  
  26.   
  27.                 DataRow dr = dt.NewRow();  
  28.   
  29.                 foreach (PropertyInfo pinfo in columns)  
  30.                 {  
  31.                     dr[pinfo.Name] = pinfo.GetValue(Record, null) == null ? DBNull.Value : pinfo.GetValue  
  32.                     (Record, null);  
  33.                 }  
  34.   
  35.                 dt.Rows.Add(dr);  
  36.             }  
  37.             return dt;  
  38.         }  
  39.   
       }  
The above function takes the LINQ query result and convert it into the Data Table

Friday, 22 August 2014

C# Enumeration

                         Follow Me To get Health tip and bodybuilding
instagram:sayyedtanveer1410



Enumeration provides efficient way to assign multiple constant integral values to a single variable. Enumeration improves code clarity and makes program easier to maintain. Enumeration in C# also provides more security by better error-checking technology and compiler warnings.
An enumeration can be defined using enum keyword. In enumeration, you can define special set of value that can be assigned with enumeration. For Example, you are creating an attendance log application in which a variable can contains value only Monday to Friday. The other value will not be applicable with variables. In order to fulfill this requirement you need to use enumeration that will hold only assigned values and will returns numeric position of values starting with zero.

using System;

namespace Enumeration
{
  // creating enumeration for storing day.
  public enum attandance
   {
     Monday,
     Tuesday,
     Wednesday,
     Thursday,
     Friday
   }

  class Program
   {
     static void Main(string[] args)
      {
        attandance present = attandance.Monday;//Valid
        Console.WriteLine(present);
           
        //attandance absent = attandance.Sunday;//Invalid
        Console.ReadLine();
      }
   }
}

output
Monday 

Thursday, 7 August 2014

Different types of WCF bindings

WCF has a couple of built in bindings which are designed to fulfill some specific need. You can also define your own custom binding in WCF to fulfill your need. All built in bindings are defined in the System.ServiceModel Namespace. Here is the list of 10 built in bindings in WCF which we commonly used:
  1. Basic binding

    This binding is provided by the BasicHttpBinding class. It is designed to expose a WCF service as an ASMX web service, so that old clients (which are still using ASMX web service) can consume new service. By default, it uses Http protocol for transport and encodes the message in UTF - 8 text for-mat. You can also use Https with this binding.
  2. Web binding

    This binding is provided by the WebHttpBinding class. It is designed to expose WCF services as Http requests by using HTTP-GET, HTTP-POST. It is used with REST based services which may give output as an XML or JSON format. This is very much used with social networks for implementing a syndication feed.
  3. Web Service (WS) binding

    This binding is provided by the WSHttpBinding class. It is like as Basic binding and uses Http or Https protocols for transport. But this is designed to offer various WS - * specifications such as WS – Reliable Messaging, WS - Transactions, WS - Security and so on which are not supported by Basic binding.
       wsHttpBinding= basicHttpBinding + WS-* specification
  4. WS Dual binding

    This binding is provided by the WsDualHttpBinding class. It is like as wsHttpBinding except it sup-ports bi-directional communication means both clients and services can send and receive messages.
  5. TCP binding

    This binding is provided by the NetTcpBinding class. It uses TCP protocol for communication be-tween two machines with in intranet (means same network). It encodes the message in binary format. This is faster and more reliable binding as compared to the Http protocol bindings. It is only used when communication is WCF - to – WCF means both client and service should have WCF.
  6. IPC binding

    This binding is provided by the NetNamedPipeBinding class. It uses named pipe for Communication between two services on the same machine. This is the most secure and fastest binding among all the bindings.
  7. MSMQ binding

    This binding is provided by the NetMsmqBinding class. It uses MSMQ for transport and offers sup-port to disconnected message queued. It provides solutions for disconnected scenarios in which service processes the message at a different time than the client send the messages.
  8. Federated WS binding

    This binding is provided by the WSFederationHttpBinding class. It is a specialized form of WS binding and provides support to federated security.
  9. Peer Network binding

    This binding is provided by the NetPeerTcpBinding class. It uses TCP protocol but uses peer net-working as transport. In this networking each machine (node) acts as a client and a server to the other nodes. This is used in the file sharing systems like torrent.
  10. MSMQ Integration binding

    This binding is provided by the MsmqIntegrationBinding class. This binding offers support to communicate with existing systems that communicate via MSMQ.

Tuesday, 5 August 2014

code to download .apk file from website in asp.net

  Follow Me To get Health Tip and bodybuilding Tip
instagram:sayyedtanveer1410



It is often a common requirement in a web application to have the ability to download some sort of file to the client's computer. Nowadays android application(.apk) are also be download from web application
so we need to know the mime type of android apk.
mimeType="application/vnd.android.package-archive"

Download Code:

 string FilePath = Server.MapPath("~/Files/Android.apk");

 Response.AppendHeader("content-disposition", "attachment; filename=" + Path.GetFileName(FilePath));

 Response.ContentType = "application/vnd.android.package-archive";                     

 Response.WriteFile(FilePath);


Note :Once you download .apk file from web application  and it can't be opened from the Browser please check it's mime type

Wednesday, 4 June 2014

Creating Maps Using Custom Maps for Google Maps and Embed on Website

Let's get started!

1. Go to Google Maps.

2.Sign in to your Google Account .After login you will see below image

3. Click the Create Map button.Select create new map.
4.Type in search box address to find map address.
5.Click on Share button on right top corner .Doing share map will be use publicly. and save it.



6. After clicking on done button .go and select iframe link and copy past in webpage.







Enjoy.........

Wednesday, 6 November 2013

Removing White spaces whithin the string

Sometimes we come across situation where we need to remove the whitespace whithin the string.
So here is the simple code for the same.

Step 1: Markup of the page

<asp:TextBox ID="txtAddress" runat="server" TextMode="MultiLine" Columns="20"
            Width="300px" style="height: 300px"></asp:TextBox>
        <br />
        <asp:Button ID="btnCheckAddress" runat="server" Text="Validate Space"
            onclick="btnCheckAddress_Click" />



Step 2: Code

protected void btnCheckAddress_Click(object sender, EventArgs e)
    {
        txtAddress.Text= txtAddress.Text.Trim();//To clear leading and trailing space

        // Following loop is to remove the whitespace within the string
        while (txtAddress.Text.Contains("  "))/Here Contains method check for 2 continues space
        {
            txtAddress.Text = txtAddress.Text.Replace("  ", " ");//Here Replace method will replace 2 continues space with single space
        }
    }


Output: