Sunday, June 19, 2016

Image width and height in asp.net c#

In this article, I am going to explain how to find out uploaded image dimension in asp. net c#.

Code of aspx page

<%@ 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">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:FileUpload ID="fupload" runat="server" />
    <asp:Button ID="btnCheckHeightWidth" runat="server" Text="Check"
            onclick="btnCheckHeightWidth_Click" /><asp:Label ID="lblmsg" runat="server" ForeColor="Green"></asp:Label>
    </div>
    </form>
</body>
</html>

Code of cs page

using System;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void btnCheckHeightWidth_Click(object sender, EventArgs e)
    {
        System.IO.Stream stream = fupload.PostedFile.InputStream;
        System.Drawing.Image image = System.Drawing.Image.FromStream(stream);
        lblmsg.Text = "Image size is " + image.Width + "x" + image.Height + " px";
    }
}

Image


Output


Friday, June 17, 2016

update controls outside updatepanel c#

In this article, I am going to explain how to update Control value or any other ASP. net control which reside out side update panel.

Let's take a example, suppose I have a button inside update panel and click on that button I want to assign some value in textbox.

Here the aspx Code

<%@ 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">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="scmain" runat="server"></asp:ScriptManager>
 
    <asp:UpdatePanel ID="upmain" runat="server">
    <ContentTemplate>
     <fieldset>
    <legend>Button Inside Update Panel</legend>
    <asp:Button ID="btnUpdateValue" runat="server" Text="UpdateValue"
             onclick="btnUpdateValue_Click" />
    </fieldset>
    </ContentTemplate>
    </asp:UpdatePanel>
 
     <asp:UpdatePanel ID="uptextbox" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
    <fieldset>
    <legend>Out Side TextBox of Update Panal</legend>
    <asp:TextBox ID="txtvalue" runat="server"></asp:TextBox>
    </fieldset>
    </ContentTemplate>
    </asp:UpdatePanel>
 
    </form>
</body>
</html>

Here the aspx.cs Code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void btnUpdateValue_Click(object sender, EventArgs e)
    {
        txtvalue.Text = "Verified";
        uptextbox.Update();
    }
}

Output




Saturday, June 11, 2016

Write a program to find GCD of 2 numbers in C#.NET



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication17
{
    class Program
    {
        static void Main()
        {
            int i, i1;

            Console.WriteLine("Enter 2 numbers to find GCD");
            i = int.Parse(Console.ReadLine());
            i1 = int.Parse(Console.ReadLine());

            int num, num1;
      
            if (i > i1)
            {
                num = i;
                num1 = i1;
            }
            else
            {
                num = i1;
                num1 = i;
            }
            int output = gcd(num, num1);
            Console.WriteLine("The GCD of {0} and {1} is {2}", i, i1, output);
            Console.Read();
        }

        private static int gcd(int num, int num1)
        {
            int rem = 5;
            while (num1 > 0)
            {
                rem = num % num1;
                if (rem == 0)
                    return num1;
                num = num1;
                num1 = rem;

            }

            return num;

        }
    }
}

Output : 



Wednesday, June 8, 2016

Write a Program to convert Decimal to Binary in C#.NET

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication16
{
    class Program
    {
        static void Main()
        {
            int num;
            Console.Write("Enter a Number : ");
            num = int.Parse(Console.ReadLine());
            int q;
 
            string rem = "";
 
            while (num >= 1)
            {
                q = num / 2;
                rem += (num % 2).ToString();
                num = q;
            }
 
 
            string b = "";
            for (int i = rem.Length - 1; i >= 0; i--)
            {
                b = b + rem[i];
 
            }
 
            Console.WriteLine("The Binary num of given number is {0}", b);
 
 
            Console.Read();
 
        }
    }

}

Output :

Tuesday, June 7, 2016

Write program to find LCM of 2 numbers in C# .NET

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication15
{
    public class LCM
    {
        public static int dLCM(int a, int b)
        {
            int n1, n2;
            if (a > b)
            {
                n1 = a; n2 = b;
            }
            else
            {
                n1 = b; n2 = a;
            }
 
            for (int i = 1; i <= n2; i++)
            {
                if ((n1 * i) % n2 == 0)
                {
                    return i * n1;
                }
            }
            return n2;
        }
 
        public static void Main(String[] args)
        {
            int n01, n02;
 
            Console.WriteLine("Enter 2 numbers :");
 
            n01 = int.Parse(Console.ReadLine());
            n02 = int.Parse(Console.ReadLine());
 
            int l = dLCM(n01, n02);
 
            Console.WriteLine("LCM of {0} and {1} is {2}", n01, n02, l);
            Console.Read();
        }
    }

}

Output : 

Monday, June 6, 2016

sql server query shortcuts

In daily life developer needs to execute different type of sql query , Lets suppose that you want to fetch data from a table so for that the query will be "select * from table-name", As per on developer terms they executes selcet * query many times on daily basis. So for daily use these shortcuts will come handy to you.
 

Click on "Option" menu, Click on "Keyboard" menu item.



Click On "OK"



Now , write the table name, select that table name and press "ctrl+3" you employee table return data


You can create many of shortcut as per your need.

Write a program to reverse a string in C# .Net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication14
{
    class StringReverse
    {
        static void Main()
        {
 
            string S, rev = "";
            Console.Write("Enter A String ");
            S = Console.ReadLine();
 
            for (int i = S.Length - 1; i >= 0; i--)
            {
 
                rev = rev + S[i];
            }
 
            Console.WriteLine("Reverse  String  Is  {0}", rev);
            Console.ReadLine();
        }
    }

}

Output :