Using Reflection to set a Property with a type of List

HI friend

I use reflection to create a generic List with a custom class (List<CustomClass>).
use this Code,

class Properties
{
    public string ProData { get; set; }
}
class Program
{
    static void Main()
    {
     Type type = typeof(Properties); // possibly from a string
     IList list = (IList) Activator.CreateInstance(
            typeof(List<>).MakeGenericType(type));

        object obj = Activator.CreateInstance(type);
        type.GetProperty("ProData").SetValue(obj, "abc", null);
        list.Add(obj);
    }
}

0 comments:

How to get XML Document from String

Hi friends

Here i am going to show you how to get XML data in the form of Text or String into the data source .
if we have a string data having a XML data like this,

string sXmlString="<parameters><Parameter><Name>Name</Name><Value>Rajesh</Value></Parameter><Parameter><Name>City</Name><Value>Jaipur</Value></Parameter><Parameter><Name>Phone No</Name><Value>12345678</Value></Parameter><Parameter><Name>State</Name><Value>Rajasthan</Value></Parameter><Parameter><Name>Pin</Name><Value>302020</Value></Parameter><Parameter><Name>Country</Name><Value>India</Value></Parameter></parameters>";

       XDocument doc = XDocument.Parse(sXmlString);
        XElement root = doc.Root;
        DataSet dataSet = new DataSet();
        dataSet.ReadXml(new StringReader(doc.ToString()));
        GridView1.DataSource = dataSet.Tables[0];
        GridView1.DataBind();
 //Here Parse Method use to Parse the string type of data to the Xml document type.

The Grid will show data like this



1 comments:

Dynamic AJAX Control Toolkit – Calendar Extender

Hi friend,
Some time we need to bind any server side control from code behind i.e .cs file of aspx page .for example
if i want to create a Text box form code behind we simple create an object of Text Box for example


            TextBox txtDate = new TextBox();
            txtDate.ID = "txtDate";
            phDate.Controls.Add(txtDate); // here phDate is a Place holder on Aspx Page

            //Now we need to add a Ajax Calendar Extender at Text Box so we should add Calendar dynamically on the code behind.

            AjaxControlToolkit.CalendarExtender calenderDate = new AjaxControlToolkit.CalendarExtender();
            calenderDate.ID = "calenderDate";
            calenderDate.TargetControlID = "txtDate";
            calenderDate.Format = "dd/MM/yyy";
            phDate.Controls.Add(calenderDate);]


 finally we get a dynamically control render on the page like this ,

0 comments:

SQL Server Date Formats

One of the most frequently asked questions in SQL Server forums is how to format a datetime value or column into a specific date format.  Here's a summary of the different date formats that come standard in SQL Server as part of the CONVERT function.  Following the standard date formats are some extended date formats that are often asked by SQL Server developers.
It is worth to note that the output of these date formats are of VARCHAR data types already and not of DATETIME data type.  With this in mind, any date comparisons performed after the datetime value has been formatted are using the VARCHAR value of the date and time and not its original DATETIME value.

Standard Date Formats
Date FormatStandardSQL StatementSample Output
Mon DD YYYY 1
HH:MIAM (or PM)
DefaultSELECT CONVERT(VARCHAR(20), GETDATE(), 100)Jan 1 2005 1:29PM 1
MM/DD/YYUSASELECT CONVERT(VARCHAR(8), GETDATE(), 1) AS [MM/DD/YY]11/23/98
MM/DD/YYYYUSASELECT CONVERT(VARCHAR(10), GETDATE(), 101) AS [MM/DD/YYYY]11/23/1998
YY.MM.DDANSISELECT CONVERT(VARCHAR(8), GETDATE(), 2) AS [YY.MM.DD]72.01.01
YYYY.MM.DDANSISELECT CONVERT(VARCHAR(10), GETDATE(), 102) AS [YYYY.MM.DD]1972.01.01
DD/MM/YYBritish/FrenchSELECT CONVERT(VARCHAR(8), GETDATE(), 3) AS [DD/MM/YY]19/02/72
DD/MM/YYYYBritish/FrenchSELECT CONVERT(VARCHAR(10), GETDATE(), 103) AS [DD/MM/YYYY]19/02/1972
DD.MM.YYGermanSELECT CONVERT(VARCHAR(8), GETDATE(), 4) AS [DD.MM.YY]25.12.05
DD.MM.YYYYGermanSELECT CONVERT(VARCHAR(10), GETDATE(), 104) AS [DD.MM.YYYY]25.12.2005
DD-MM-YYItalianSELECT CONVERT(VARCHAR(8), GETDATE(), 5) AS [DD-MM-YY]24-01-98
DD-MM-YYYYItalianSELECT CONVERT(VARCHAR(10), GETDATE(), 105) AS [DD-MM-YYYY]24-01-1998
DD Mon YY 1-SELECT CONVERT(VARCHAR(9), GETDATE(), 6) AS [DD MON YY]04 Jul 06 1
DD Mon YYYY 1-SELECT CONVERT(VARCHAR(11), GETDATE(), 106) AS [DD MON YYYY]04 Jul 2006 1
Mon DD, YY 1-SELECT CONVERT(VARCHAR(10), GETDATE(), 7) AS [Mon DD, YY]Jan 24, 98 1
Mon DD, YYYY 1-SELECT CONVERT(VARCHAR(12), GETDATE(), 107) AS [Mon DD, YYYY]Jan 24, 1998 1
HH:MM:SS-SELECT CONVERT(VARCHAR(8), GETDATE(), 108)03:24:53
Mon DD YYYY HH:MI:SS:MMMAM (or PM) 1Default +
milliseconds
SELECT CONVERT(VARCHAR(26), GETDATE(), 109)Apr 28 2006 12:32:29:253PM 1
MM-DD-YYUSASELECT CONVERT(VARCHAR(8), GETDATE(), 10) AS [MM-DD-YY]01-01-06
MM-DD-YYYYUSASELECT CONVERT(VARCHAR(10), GETDATE(), 110) AS [MM-DD-YYYY]01-01-2006
YY/MM/DD-SELECT CONVERT(VARCHAR(8), GETDATE(), 11) AS [YY/MM/DD]98/11/23
YYYY/MM/DD-SELECT CONVERT(VARCHAR(10), GETDATE(), 111) AS [YYYY/MM/DD]1998/11/23
YYMMDDISOSELECT CONVERT(VARCHAR(6), GETDATE(), 12) AS [YYMMDD]980124
YYYYMMDDISOSELECT CONVERT(VARCHAR(8), GETDATE(), 112) AS [YYYYMMDD]19980124
DD Mon YYYY HH:MM:SS:MMM(24h) 1Europe default + millisecondsSELECT CONVERT(VARCHAR(24), GETDATE(), 113)28 Apr 2006 00:34:55:190 1
HH:MI:SS:MMM(24H)-SELECT CONVERT(VARCHAR(12), GETDATE(), 114) AS [HH:MI:SS:MMM(24H)]11:34:23:013
YYYY-MM-DD HH:MI:SS(24h)ODBC CanonicalSELECT CONVERT(VARCHAR(19), GETDATE(), 120)1972-01-01 13:42:24
YYYY-MM-DD HH:MI:SS.MMM(24h)ODBC Canonical
(with milliseconds)
SELECT CONVERT(VARCHAR(23), GETDATE(), 121)1972-02-19 06:35:24.489
YYYY-MM-DDTHH:MM:SS:MMMISO8601SELECT CONVERT(VARCHAR(23), GETDATE(), 126)1998-11-23T11:25:43:250
DD Mon YYYY HH:MI:SS:MMMAM 1KuwaitiSELECT CONVERT(VARCHAR(26), GETDATE(), 130)28 Apr 2006 12:39:32:429AM 1
DD/MM/YYYY HH:MI:SS:MMMAMKuwaitiSELECT CONVERT(VARCHAR(25), GETDATE(), 131)28/04/2006 12:39:32:429AM


Here are some more date formats that does not come standard in SQL Server as part of the CONVERT function.
Extended Date Formats
Date FormatSQL StatementSample Output
YY-MM-DD
SELECT SUBSTRING(CONVERT(VARCHAR(10), GETDATE(), 120), 3, 8) AS [YY-MM-DD]
SELECT REPLACE(CONVERT(VARCHAR(8), GETDATE(), 11), '/', '-') AS [YY-MM-DD]
99-01-24
YYYY-MM-DD
SELECT CONVERT(VARCHAR(10), GETDATE(), 120) AS [YYYY-MM-DD]
SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 111), '/', '-') AS [YYYY-MM-DD]
1999-01-24
MM/YYSELECT RIGHT(CONVERT(VARCHAR(8), GETDATE(), 3), 5) AS [MM/YY]
SELECT SUBSTRING(CONVERT(VARCHAR(8), GETDATE(), 3), 4, 5) AS [MM/YY]
08/99
MM/YYYYSELECT RIGHT(CONVERT(VARCHAR(10), GETDATE(), 103), 7) AS [MM/YYYY]12/2005
YY/MMSELECT CONVERT(VARCHAR(5), GETDATE(), 11) AS [YY/MM]99/08
YYYY/MMSELECT CONVERT(VARCHAR(7), GETDATE(), 111) AS [YYYY/MM]2005/12
Month DD, YYYY 1SELECT DATENAME(MM, GETDATE()) + RIGHT(CONVERT(VARCHAR(12), GETDATE(), 107), 9) AS [Month DD, YYYY]July 04, 20061
Mon YYYY1SELECT SUBSTRING(CONVERT(VARCHAR(11), GETDATE(), 113), 4, 8) AS [Mon YYYY]Apr 2006 1
Month YYYY 1SELECT DATENAME(MM, GETDATE()) + ' ' + CAST(YEAR(GETDATE()) AS VARCHAR(4)) AS [Month YYYY]February 2006 1
DD Month1SELECT CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' + DATENAME(MM, GETDATE()) AS [DD Month]11 September 1
Month DD1SELECT DATENAME(MM, GETDATE()) + ' ' + CAST(DAY(GETDATE()) AS VARCHAR(2)) AS [Month DD]September 11 1
DD Month YY 1SELECT CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' + DATENAME(MM, GETDATE()) + ' ' + RIGHT(CAST(YEAR(GETDATE()) AS VARCHAR(4)), 2) AS [DD Month YY]19 February 72 1
DD Month YYYY 1SELECT CAST(DAY(GETDATE()) AS VARCHAR(2)) + ' ' + DATENAME(MM, GETDATE()) + ' ' + CAST(YEAR(GETDATE()) AS VARCHAR(4)) AS [DD Month YYYY]11 September 2002 1
MM-YYSELECT RIGHT(CONVERT(VARCHAR(8), GETDATE(), 5), 5) AS [MM-YY]
SELECT SUBSTRING(CONVERT(VARCHAR(8), GETDATE(), 5), 4, 5) AS [MM-YY]
12/92
MM-YYYYSELECT RIGHT(CONVERT(VARCHAR(10), GETDATE(), 105), 7) AS [MM-YYYY]05-2006
YY-MMSELECT RIGHT(CONVERT(VARCHAR(7), GETDATE(), 120), 5) AS [YY-MM]
SELECT SUBSTRING(CONVERT(VARCHAR(10), GETDATE(), 120), 3, 5) AS [YY-MM]
92/12
YYYY-MMSELECT CONVERT(VARCHAR(7), GETDATE(), 120) AS [YYYY-MM]2006-05
MMDDYYSELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 1), '/', '') AS [MMDDYY]122506
MMDDYYYYSELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 101), '/', '') AS [MMDDYYYY]12252006
DDMMYYSELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 3), '/', '') AS [DDMMYY]240702
DDMMYYYYSELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 103), '/', '') AS [DDMMYYYY]24072002
Mon-YY 1SELECT REPLACE(RIGHT(CONVERT(VARCHAR(9), GETDATE(), 6), 6), ' ', '-') AS [Mon-YY]Sep-02 1
Mon-YYYY1SELECT REPLACE(RIGHT(CONVERT(VARCHAR(11), GETDATE(), 106), 8), ' ', '-') AS [Mon-YYYY]Sep-2002 1
DD-Mon-YY 1SELECT REPLACE(CONVERT(VARCHAR(9), GETDATE(), 6), ' ', '-') AS [DD-Mon-YY]25-Dec-05 1
DD-Mon-YYYY 1SELECT REPLACE(CONVERT(VARCHAR(11), GETDATE(), 106), ' ', '-') AS [DD-Mon-YYYY]25-Dec-20051
1 To make the month name in upper case, simply use the UPPER string function.

0 comments:

Run a .sql script files in C#

Hi friend 


Here i am writing the code which is used to execute .sql script file from any location used to create database.
 for this we need to use some namespace like,System.Data.SqlClient, using System.IO, Microsoft.SqlServer.Management.Common, Microsoft.SqlServer.Management.Smo


using System.Configuration;
using System.Data;
using  System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Data.SqlClient;
using System.IO;
using Microsoft.SqlServer.Management.Common;
using Microsoft.SqlServer.Management.Smo;

public partial class _1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        string sqlConnectionString = @"Data Source=PS135\SQLEXPRESS;Initial Catalog=Dummy;Integrated Security=True;";  //this is a connection  string use to connect with database .

        FileInfo file = new FileInfo("C:\\Dummy.sql"); //Location of the .sql file

        string script = file.OpenText().ReadToEnd();

        SqlConnection con = new SqlConnection(sqlConnectionString);

        Server server = new Server(new ServerConnection(con));//Initializes a new instance of the ServerConnection class with the specified connection parameters.

        server.ConnectionContext.ExecuteNonQuery(script);


    }
}
 
Hope it helps you ......

0 comments:

Throwing an Exception in C#


In C#, it is possible to throw an exception programmatically. The ‘throw’ keyword is used for this purpose. The general form of throwing an exception is as follows.
throw exception_obj;
Here I am explain you how throw an exception on the other Error page with the help of Global.asax file
we use try and catch block for exception handling .
 try
        {
            //logical part
        }
 catch (Exception ex)
        {
            throw (ex);
        }

we need Global.asax file for that , so simply create Gloal.asax file for this propose .
Here we need to write code on function Applicaion_Error and redirect the QueryString having Error type message to the page where we want to show the Error Message.

void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

        Exception ex = Server.GetLastError().GetBaseException();

       
        Response.Redirect("ErrorPage.aspx?error=" + ex.Message);

    }

// GetLastError() use to get the current error

Here on the ErrorPage.aspx Page we get the Querystring and show the message ob label 

  lblErrorMessage.Text= Request.QueryString[0].ToString();

0 comments:

Resource Files in ASP.NET

A resource file is an XML file that contains the strings that you want to translate into different languages or paths to images.The resource file contains key/value pairs. Each pair is an individual resource. Key names are not case sensitive.

Types of Resources:
There are two types of resources in asp.net ,
  1. Local Resources
  2. Global Resources
    Local Resources 

    • Local resource is specific to a single Web page and used for providing versions of a Web page in different languages.
    • Local resources must be stored in App_LocalResources sub folder. for Example Default.aspx.resx.
      How to create local Resource file 

      for example you want and to create local resource file for Default.aspx page then open the page and select tool menu 

      Tools-->Generate Local Resources 
      this will create App_LocalResources folder with Text and ToolTip values for all existing controls on the page, as well as the page title will be generated.
      the file Default.aspx.resx. look like this .
       How to access the resource file 
      1. Access Resource file on Source file :- If you want to use an value from Default.aspx.resx on the lable use this syntex,                                                       <asp:Label ID="lblMessage" runat="server" Text="<%$ Resources:Default, PageResource1.Title%>"></asp:Label>                                                                   <%$ Resources:Class, ResourceID %>

        Where Class:
        Identifies the resource file to be used
        ResourceID: Identifier of the resource to be read from resource file                         
      2. Access Resource file on the .cs file :-If you want to use the resource file on .cs file use this syntex.  (string)GetLocalResourceObject("ResourceID"); 
      Global Resource File
      • Global resource can be read from any page or code that is in the application.
      • Global resource must be stored in App_GlobalResources at the root of the application.
        How to create Global file 
        Right click on Solution Explorer--> Add New Item-->Resource File
        How to use Global file
      1)On Source file :- Text="<%$ Resources:Default,Global, ResourceID%>">
      2)On .cs file :-String test=Resources.Global.ResourceID;


0 comments:

C#.NET: How to create ASP.NET web service


Hi Friends,
 Here i am writing a code for Web services means how to create and user a simple example of web services into your asp.net application using C#.
 
To create your first web service project, just follow these steps:
1. Open your Visual Studio .NET and click File > New Website. This will display the project templates. Choose ASP.NET Web Service from the installed templates as shown below.



2. Visual Studio .NET should generate your first Hello web service method. Lets add another web service method.

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;

namespace WebService1
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
    // [System.Web.Script.Services.ScriptService]
    public class Service1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }
        [WebMethod]
        public int AddTwo(int n1,int n2)
        {
            return n1 + n2;
        }
    }
}

if you can notice the obvious difference of our web service method with an ordinary C#  method is this additional attribute before the function name:
[WebMethod] //this will indicate that this is a Web service method


It tells the framework that the following method is a web service.

3. To test the web service project, Click the Start Debugging Visual Studio will automatically open your default web browser and display all available web service method.








4. Now lets test one of the web service method. Click the Addthis method. You should be forwarded to the following page:




AddThis requires two parameters. Try to put numbers on each textbox then click Invoke. The web service method will return an XML result like the one below:



After Creating this web Services you can use this web services into your web application lets take an example for that , I have a button on the click event I simple user the Web services with Add Method ,

protected void Button1_Click(object sender, EventArgs e)
        {
            Service1 obj = new Service1();
            Label1.Text = obj.AddTwo(Convert.ToInt32(TextBox1.Text), Convert.ToInt32(TextBox2.Text)).ToString(); ;

        }
Here Service1 is the Webservice file name 

Hope this code also Helps you

Regards,
Rajesh 

0 comments:

Maintain the Scroll Position on the ASPX page

Hi Friend ,
you know what ,By Default postback property of the page  set the scroll position at top position of the page but we can use a the following statatement to retain the position. 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebAgain._Default" MaintainScrollPositionOnPostback="true" %> 

Hope this is help you 

Regards,

Rajesh 

1 comments:

Date time format in ASP.Net


Here are some custom formats of date time in ASP.Net:

 string date = DateTime.Now.Date; //This will show the Current Date

 
1) date.DayOfWeek + " " + date.Day + " " + date.ToString("MMMM") + " " + date.Year.ToString()

Example it will shown as “Monday 18 October 2010 ”

 2) date.DayOfWeek + " " + date.Day + " " + date.ToString("MMMM") + " " + date.ToString("HH:mm:ss")

It will show time as “Monday 18 October 21:00:13 ” with Hr format

 3) date.DayOfWeek + " " + date.Day + " " + date.ToString("MMMM") + " " + date.ToString("hh:PM:mm:ss:tt")

It will show time as “Monday 18 October 21:00:13 PM” with Hr format with AM/PM

You also set format like this :-

DateTime.Now.ToString("MM/dd/yyyy");

DateTime.Now.ToString("MMM dd yyyy");

DateTime.Now.ToString("dd/MM/yyyy

0 comments:

Send mail with an Attachment

Hi friend

Hers is the code which show the Email Send with the attached file .Have a look..


using System;
using System.Data;
using System.Configuration;
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.Net.Mail;
 
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void btnMailSend_Click(object sender, EventArgs e)
    {
        MailMessage mail = new MailMessage();
        mail.To.Add(“SendToMail@gmail.com”);
        //To whome you want to send mail
        mail.From = new MailAddress(“SemderMailId@yahoo.com”);
        mail.Subject = “This is a Subject of the Mail”;
        mail.Body = “Here We Add the Body of the mail”;
        mail.IsBodyHtml = true;
//Here We attached the File 
        if (FileUpload1.HasFile)
        {
            mail.Attachments.Add(new Attachment(FileUpload1.PostedFile.InputStream, FileUpload1.FileName));
        }
        SmtpClient smtp = new SmtpClient();
        smtp.Host = "smtp.gmail.com"; 
        smtp.Credentials = new System.Net.NetworkCredential
             ("YourMailID@gmail.com", "Password");
 //It may be your Smtp Email ID and Password
        smtp.EnableSsl = true;
        smtp.Send(mail);
 
    }
}

1 comments:

How to render any web site page on Your web page

Hi friends
 To day i have some thing new code for you in this i'll show you how to get or render any web page like yahoo.com home page  or any xyz web page on your web application .aspx page . hope it sound interesting to you.  


 1) Lets start first create any web application and create a web page ex. New.aspx thats my aspx page where i want to render http://itneeds4u.blogspot.com/ website home page .
2) After creation of that page put a lable on it and set Text property =This is a Lable . after this run this page you will get a page out put like this ..

After this put a code at the page load of New.aspx.cs

public partial class New : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // The System.Text.StringBuilder class can be used when you want to modify a string without creating a new object. Here we used to create entire input
            StringBuilder sb = new StringBuilder();

            // used on each read operation
            byte[] buf = new byte[8192];

            // Here We requet for that page which we want to render on our web page
            HttpWebRequest request = (HttpWebRequest)
            WebRequest.Create("http://itneeds4u.blogspot.com");//Put your url here

            // This wil execute the request
            HttpWebResponse response = (HttpWebResponse)
            request.GetResponse();

            // Here this object read data from responce strem
            Stream responseStream = response.GetResponseStream();

            string tempString = null;
            int count = 0;

            do
            {
                // Here fill the Buffer with data
                 count = responseStream.Read(buf, 0, buf.Length);

               
                if (count != 0)
                {
                    // Here we translate  bytes to ASCII text
                    tempString = Encoding.ASCII.GetString(buf, 0, count);

                    // Create a Proper web text.
                    sb.Append(tempString);

                }
            }
            while (count > 0); // any more data to read?


          lblOutput.Text = sb.ToString();         

        }
    }
after this the web site page will render on your simple aspx page and it will show on the lable .and after this your New.aspx  will be look like this .


this kind of code also help you to find any specify information from other page also..
hope this information is helpful to you.

Regards,

Rajesh

1 comments:

Search Engine Optimization



Search Engine Optimization(SEO), is a technique which can make websites search engine friendly and ensure high ranking in search engine results pages. High ranking in means more targeted visitors and excellent business opportunities for free of cost.
By following are  SEO strategies that apply on the web page.
1.        Your website Should indexed in search engines and directories.
2.        Your websites are being displayed & ranking high in Search result pages.
3.        Your page rank should increased and it  getting more traffic.
4.        Check your web site orientation that must be in order to support SEO tactics .
Some important factor which makes SEO perfect at your web site.

Website Design Factor

You should design the web site including links, headers, alternative image text, alternative frame text and content text in such a way that it is easily crawled by the web crawler.

User Friendliness

Your web site should be user friendly its means it maintain proper page path means should not take more time to navigate on any page.


Content of the Website

Should avoid the copied content on your web site. You should create your own content for your website. You web site page title, page description, keywords, and file name should be well optimized in order to get high ranking in the search engines.

These days google is one of the best search engine and if your site is get indexed in the google, you will start getting tons of hits to your web site.

SEO are of two kind :-
1)      On-page optimization
2)      Off- page optimization.

On-page optimization

In search engine optimization, on-page optimization refers to factors that have an effect on your Web site or Web page listing in natural search results. These factors are controlled by you or by coding on your page. Examples of on-page optimization include actual HTML code, meta tags, keyword placement and keyword density.
Some Point to be remember for on page optimization
Ø      Title Tag :- The first thing to add a Page title having a right keyword of that web site which have to place at the header teg , always combile a keyword with the title.
Ex.<Title> This is a Title of the page</Title>
Ø      Header:- You should highlight the web site keyword with the Header tag .
Ø      Robots Text File - robots.txt The robots.txt file is a set of instructions for visiting robots (spiders) that index the content of your web site pages. For those spiders that obey the file, it provides a map for what they can, and cannot index. The file must reside in the root directory of your web. The URL path (web address) of your robots.txt file should look like this...
User-agent: *
Disallow:
User-agent: *
The asterisk (*) or wildcard represents a special value and means any robot.
Disallow:
The Disallow: line without a / (forward slash) tells the robots that they can index the entire site.
Ø      META Tags - Metadata Elements :- Meta tags are often part of the coding of a website, although they are being found less and less these days. Meta tags are elements of the web page language HTML or XHTML that provide metadata, data or information for the search engines about that webpage. Meta tags can be used to detail the page description, keywords and other data not specified in the head elements of the page.

Meta Tag should be in between head tag in which we maintain a mata tag
Example:-

i)                    <meta name="description" content="Some search engines will index the META Description Tag. These indexing search engines may present the content of your meta description tag as the result of a search query.">
ii)                   <meta name="keywords" content="META Keywords Tag, Metadata Elements, Indexing, Search Engines, Meta Data Elements">
iii)                 <meta http-equiv="content-language" content="en">
          
Ø       Keyword intensity :-Higher intensity of key work on the page will support a better page rank on the search engine . make it confirm that every page have the better density on keyword.
Ø       Keywork location :-Website Key word should be mention at the top-left corner and at the bottom right because search engine will search at both the locations.


Off Page Optimization

In search engine optimization, off-page optimization refers to factors that have an effect on your Web site or Web page listing in natural search results. These factors are off-site in that they are not controlled by you or the coding on your page. Examples of off-page optimization include things such as link popularity and page rank.


This includes,

o       Which website link to you.
o       Number of website link to you.
o       Higher google page rank site linking to you.
o       Some API of Web site linking to you.
o       Other refer sites linking to you.
o       The title of the page your link is on
o       Anchor text used in the link
o       Online promotion of your site.


8 comments:

Send mail Using Gmail Account

Hi Friends,

Here i am posting a function which help to send a email from gmail account to your customer's account . in which you maintain account details and a complete format of mail .  


private void Email_User(string Account_No, string Email, string userName)
        {
            // Here Account_No is the New Account No that you what to send
           //Email is a email address of that person whom you want to send mail
          // userName is the name of that person
            try
            {
                string mail_id = Email;
                MailMessage mm = new MailMessage("dummy@gmail.com", mail_id);
                mm.Subject = "Successful Account Registration";
                mm.Body = "Dear " + userName + "," + "\n" + "Your registration is NOT yet complete! You must login to your account to activate it and complete your registration!" + "\n" + "" + "\n" + "===========================================" + "\n\n\n" + "Your  Account account number: " + Account_No + " \n\n\n" + "============================================" + "\n\n" + "Reminder: You must login to your account in order to activate it." + "\n\n" + "For inqueries and support please use our contact form." + "\n\n" + "Thank you." + "\n\n" + "===========================================" + "\n" + "Keep your account secure by following these simple rules:" + "\n" + "Do NOT click on any links!" + "\n" + "We will always address you by your first name." + "\n" + "We will never send you attached files or ask you to update your login information." + "\n" + "Contact us if you are unsure about an email you received." + "\n" + "============================================";
                SmtpClient smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.EnableSsl = true;
                System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
                NetworkCred.UserName = "dummy@gmail.com ";//Sender mailid
                NetworkCred.Password = "dummy123";//Sender Mail password
                smtp.UseDefaultCredentials = true;
                smtp.Credentials = NetworkCred;
                smtp.Port = 587;
                smtp.Send(mm);
               
            }
            catch (Exception ex)
            {
            }
        }

This Email Should be look like this 

Regards ,
Rajesh

1 comments:

Random Password Generator

Hi friend ,
Here i am giving you a C# function which is used to generate random password . It might be between 1 to 9,a to z, A to Z . new password is a combination of all these characters.
 look @ the function,


private string Random_Password()
   { 
 int passwordLength = 8; //This is the length of your password
      string passwordChar = "";
      passwordChar = "a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,";
      passwordChar += "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,";
      passwordChar += "1,2,3,4,5,6,7,8,9,0";
      char[] sep = { ',' };
      string[] arr = passwordChar.Split(sep);
      string passwordString = "";
      string temp = "";             
      Random rand = new Random();
      for(int i = 0; i < Convert.ToInt32(passwordLength.ToString()); i++)
           {
             temp = arr[rand.Next(0, arr.Length)];
             passwordString += temp;
            }

            return passwordString;
   }

This function will return a 8 digit alpha numeric password . hope this will help you in your project.

Regards,

Rajesh

1 comments:

Multithreading in C#

What is Multithreading in C#.

Multithreading gives programs the ability to do several things at a time. Each stream of execution is called a thread. Multithreading is used to divide lengthy tasks into different segments that would Secondary  threadwise abort programs. Threads are mainly used to utilize the processor to a maximum extent by avoiding it's idle time. Threading lets a program seem as if it is executing several tasks at once. What actually happens is, the time gets divided by the computer into parts and when a new thread starts, that thread gets a portion of the divided time. Threads in VB .NET are based on the namespace System.Threading. Represents a thread that executes with in theCLR. Using this type, one can able to spawn additional threads in theowning AppDomain.This type defines a number of methods (both static andshared) that allow us to create new threads from a current thread, aswell as suspend, stop, and destroy a given thread.
The following example will demonstrate threads using C#.
using System;
using System.Threading;
 
public class Test
{
    static void Main()
    {
        ThreadStart NewThred = new ThreadStart(NewThread);
        Thread thread = new Thread(NewThred);
        thread.Start();
        
        for (int i=0; i < 5; i++)
        {
            Console.WriteLine ("Primary  thread: {0}", i);
            Thread.Sleep(1000);
        }
    }
    
    static void NewThread ()
    {
        for (int i=0; i < 10; i++)
        {
            Console.WriteLine ("Secondary thread: {0}", i);
            Thread.Sleep(500);
        }
    }
}
 
Here we creates a new thread which runs the NewThread method, and starts it. That thread counts from 0 to 9 fairly fast while the Primary thread counts from 0 to 4 fairly slowly The way they count at different speeds is by each of them including a call to Thread.Sleep, which just makes the current thread sleep for the specified period of time. Between each count in the Primary  thread we sleep for 1000ms, and between each count in the Secondary  thread we sleep for 500ms. Here are the results from one test run on my machine:
Primary thread: 0
Secondary thread: 0
Secondary thread: 1
Primary thread: 1
Secondary thread: 2
Secondary thread: 3
Primary thread: 2
Secondary thread: 4
Secondary thread: 5
Primary thread: 3
Secondary thread: 6
Secondary thread: 7
Primary thread: 4
Secondary thread: 8
Secondary thread: 9
 

1 comments: