Sunday, June 22, 2014

Thumb rules in choosing endpoint' binding

  • If you require your service to be consumed by clients compatible with SOAP 1.1, use basicHttpBinding for interoperability
  • If you require your service to be consumed within the corporate network, use netTCPBinding for performance
  • If you require your service to be consumed over the internet and the client is a WCF compatible, use wsHttpBinding to reap full benefits of WS* specifications
  • If you require your service to be accessible only in the same machine, use netNamedPipeBinding
  • If you require your service to be queue messages, use netMsmqBinding
  • If you require your service to act as server as well as client in a peer to peer environment, utilise netPeerTcpBinding setting
Binding
Security Default Configurable
Transport ProtocolEncoding Default OtherHost
basicHttpBinding
None,
Transport, Message, Mixed
HTTPText/XML, MTOMIIS, WAS
wsHttpBindingMessage, Transport, MixedHTTPText/XML, MTOMIIS, WAS
netTcpBindingTransport, Message, MixedTCPBinaryWAS
netNamedPipeBindingTransport,NoneNamed PipeBinaryWAS
netMsmqBindingMessage, Transport, NoneTCPBinaryWAS
netPeerTcpBindingTransportP2PBinary-

Tuesday, June 17, 2014

Social media code for Share in asp.net.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="tree.aspx.cs" Inherits="tree" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
<script type="text/javascript">var switchTo5x = true;</script>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({ publisher: "97fa2c8f-9b01-4cd3-85e2-9a908da2fbbe", doNotHash: false, doNotCopy: false, hashAddressBar: false });</script>
</head>
<body>
<span class='st_sharethis_large' displayText='ShareThis'></span><br />
<span class='st_facebook_large' displayText='Facebook'></span><br />
<span class='st_twitter_large' displayText='Tweet'></span><br />
<span class='st_linkedin_large' displayText='LinkedIn'></span><br />
<span class='st_pinterest_large' displayText='Pinterest'></span><br />
<span class='st_email_large' displayText='Email'></span><br />
<form id="form1" runat="server">
     
    </form>
</body>
</html>

Thursday, June 5, 2014

How to assign value from child to parent pages?

Step-1: Create parent Pages
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="Scripts/jquery-2.1.0.min.js"></script>
<head runat="server">
   <script language="javascript" type="text/javascript">
       var bankValAgency = "";
       function showSearchAgency() {
           var url = 'test.aspx';
           popup(url, '');
       }
function setAgency( agencyName) {
   debugger;
   var repAgency = String(agencyName);
   $("#<%= this.txtBxAgency.ClientID %>").val(repAgency);
}
       function popup(url, name) {
           var win = window.open(url, name, 'left=400,top=200,height=500,width=600,status=no,resizable=1,scrollbars=1,toolbar=no,location=no,menubar=no');
           win.opener = window;
           if (window.focus) win.focus();
       }
        </script>
</head>
<body>
    <form id="form1" runat="server">
     
<asp:TextBox ID="txtBxAgency" runat="server"  Width="255px" />
<a href="#" onclick=" javascript:showSearchAgency(); ">
<asp:Label ID="lblSelectAgency" Text="Search" runat="server"></asp:Label></a>
<input id="hdnAgencyId" runat="server" name="HdnAgencyId" type="hidden" />
    </form> </body >  </html >

Step-2: Create Child pages

<%@ Page Language="C#"  MasterPageFile="~/Site.Master"  AutoEventWireup="true" CodeBehind="test.aspx.cs" Inherits="WebApp.test" %>

<asp:Content runat="server" ID="FeaturedContent" ContentPlaceHolderID="FeaturedContent">
      <script language="javascript" type="text/javascript">
        function setAgency() {
            var instituteName = document.getElementById('txtInstitute').value;
            window.opener.setAgency(instituteName);
            window.close();
            return true;}
    </script>
</asp:Content>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
  <asp:TextBox ClientIDMode="Static" runat="server" ID="txtInstitute"></asp:TextBox>
  <asp:Button runat="server" ID="btnSubmit" OnClientClick="setAgency();" Text="Submit"/>
</asp:Content>

Wednesday, June 4, 2014

Include DropDown List Inside WebGrid in MVC 4.

Step-1: Make a Model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication1.Models
{
    public class EmployeeInformation
    {
        public List<Employee> EmployeeModel { get; set; }
    }
    public class Employee
    {
        public string Name { get; set; }
        public string Address { get; set; }
        public SelectList MerritalStatus { get; set; }
    }
    public class Status
    {
        public int Id { get; set; }
        public string StatusName { get; set; }
    }
}

Step-2:Coding on Controller

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;

namespace MvcApplication1.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            EmployeeInformation empobj = new EmployeeInformation();
            empobj.EmployeeModel = MerryDetail();
            return View(empobj);
        }
        public List<Employee> MerryDetail()
        {
            List<Employee> objempmodel = new List<Employee>();
            objempmodel.Add(new Employee { Name = "Employee1", Address = "Address1", MerritalStatus = GetStatus() });
            objempmodel.Add(new Employee { Name = "Employee2", Address = "Address2", MerritalStatus = GetStatus() });
            objempmodel.Add(new Employee { Name = "Employee3", Address = "Address3", MerritalStatus = GetStatus() });
            objempmodel.Add(new Employee { Name = "Employee4", Address = "Address4", MerritalStatus = GetStatus() });
            objempmodel.Add(new Employee { Name = "Employee5", Address = "Address5", MerritalStatus = GetStatus() });
            return objempmodel;
        }
        public SelectList GetStatus()
        {
            List<Status> status = new List<Status>();
            status.Add(new Status { Id = 1, StatusName = "Merried" });
            status.Add(new Status { Id = 2, StatusName = "Unmerried" });
            SelectList objinfo = new SelectList(status, "Id", "StatusName");
            return objinfo;
        }
    }
}

Step-3:View
@model MvcApplication1.Models.EmployeeInformation
@{ViewBag.Title = "Index";}
<style type="text/css">
    .gridTable {
        margin: 4px;
        padding: 10px;
        border: 1px #333 solid;
        border-collapse: collapse;
        min-width: 550px;
        background-color: #999;
        color: #999;
    }

    .gridHead th {
        font-weight: bold;
        background-color: #ffd800;
        color: #333;
        padding: 10px;
    }

    .gridHead a:link, .gridHead a:visited, .gridHead a:active, .gridHead a:hover {
        color: #333;
    }

    .gridHead a:hover {
        text-decoration: underline;
        background-color: #f67f7f;
    }

    .gridTable tr.gridAltRow {
        background-color: #c7d1d6;
    }

    .gridTable tr:hover {
        background-color: #f67f7f;
    }

    .gridAltRow td {
        padding: 10px;
        margin: 5px;
        color: #333;
    }

    .gridRow td {
        padding: 10px;
        color: #333;
    }

    .gridFooter td {
        padding: 10px;
        background-color: #c7d1d6;
        color: #999;
        font-size: 12pt;
        text-align: center;
    }

    .gridFooter a {
        font-size: medium;
        font-weight: bold;
        color: #333;
        border: 1px #333 solid;
    }
</style>
@{
    var g_style = new WebGrid(source: Model.EmployeeModel,rowsPerPage: 10);
    
    @g_style.GetHtml(
tableStyle: "gridTable",
headerStyle: "gridHead",
footerStyle: "gridFooter",
rowStyle: "gridRow",
alternatingRowStyle: "gridAltRow",
        columns: g_style.Columns(
        g_style.Column("Name", "Name"),
        g_style.Column("Address", "Address"),
        g_style.Column(header: "Status", format: @item => Html.DropDownList("value", (IEnumerable<SelectListItem>)Model.EmployeeModel[0].MerritalStatus))))

}




Monday, June 2, 2014

How to upload resize images?

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<script src="Scripts/jquery-2.1.0.min.js"></script>

<head runat="server">

<script type="text/javascript">

function readURL(input) {

if (input.files && input.files[0]) {

var reader = new FileReader();

reader.onload = function(e) {

$("#<%= this.ImgPhoto.ClientID %>").attr('src', e.target.result);



};

reader.readAsDataURL(input.files[0]);

}

}

$("#<%= this.UploadPhoto.ClientID %>").change(function () {

readURL(this);



});

</script>





</head>

<body>

<form id="form1" runat="server">

<img id="ImgPhoto" alt="Preview" width="206" height="240" runat="server" src="~/Images/NoPhoto.jpg" />

<br/>

<asp:FileUpload ID="UploadPhoto" runat="server" onchange="readURL(this)" />

<asp:Button runat="server" ID="btnsubmit" Text="Submit" OnClick="btnsubmit_Click"/>

</form>

</body>

</html>

====================

using System;

using System.IO;

using System.Data;

using System.Configuration;

using System.Globalization;

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.Drawing;

public partial class Default : System.Web.UI.Page



{
 
protected void Page_Load(object sender, EventArgs e)



{

}
 
public static Bitmap ResizePassportSize(FileUpload fp, int lnWidth, int lnHeight)



{
 
Bitmap bmpOut = null;

try



{
 
Bitmap loBmp = new Bitmap(fp.FileContent, true);

decimal lnRatio;

int lnNewWidth = 0;

int lnNewHeight = 0;

//*** If the image is smaller than a thumbnail just return it

if (loBmp.Width < lnWidth && loBmp.Height < lnHeight)

return loBmp;

if (loBmp.Width > loBmp.Height)



{
 
lnRatio = (decimal) lnWidth/loBmp.Width;



lnNewWidth = lnWidth;
 
decimal lnTemp = loBmp.Height*lnRatio;

lnNewHeight = (int) lnTemp;



}
 
else



{
 
lnRatio = (decimal) lnHeight/loBmp.Height;



lnNewHeight = lnHeight;
 
decimal lnTemp = loBmp.Width*lnRatio;

lnNewWidth = (int) lnTemp;



}
 
bmpOut = new Bitmap(lnNewWidth, lnNewHeight);

Graphics g = Graphics.FromImage(bmpOut);

g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

g.FillRectangle(Brushes.White, 0, 0, lnNewWidth, lnNewHeight);



g.DrawImage(loBmp, 0, 0, lnNewWidth, lnNewHeight);

loBmp.Dispose();

}
 
catch



{
 
return null;



}
 
return bmpOut;



}
 
protected void btnsubmit_Click(object sender, EventArgs e)



{
 
if (UploadPhoto.HasFile)



{
 
Bitmap bitmpPhoto = ResizePassportSize(this.UploadPhoto, 206, 240);

bitmpPhoto.Save(Server.MapPath("images/abc.jpg"));



}

}

}