Saturday, 22 February 2014

Linq using Orderby

This sample uses orderby and ascending to sort a list of String from lowest to highest .


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

namespace SampleLinq
{
    class Program
    {
        static void Main(string[] args)
        {
            OrderByLinQ();
        }

        private static void OrderByLinQ()
        {
            List<string> objlist = new List<string> { "Sriram", "TMS", "Ajmal", "Abdul", "Azeez", "Retheesh", "Guru", "Bala", "das" };

            var sortedWords = from w in objlist
                              orderby w
                              select w;

            Console.WriteLine("The sorted list of words:");
            foreach (var w in sortedWords)
            {
                Console.WriteLine(w);
            }
            Console.Read();
        }
    }
}

This sample uses orderby and descending to sort a list of doubles from highest to lowest.



        private static void OrderByLinQ()
        {
            List<string> objlist = new List<string> { "Sriram", "TMS", "Ajmal", "Abdul", "Azeez", "Retheesh", "Guru", "Bala", "das" };

            var sortedWords = from w in objlist
                              orderby w descending
                              select w;

            Console.WriteLine("The sorted list of words:");
            foreach (var w in sortedWords)
            {
                Console.WriteLine(w);
            }
            Console.Read();
        }
    }




LINQ Introduction

Introduction
  • LINQ is a new technology introduced in .NET 3.5
  • LINQ is acronym for Language Integrated Query
  • The LINQ feature is one of the major differences between the .NET 3.0 and .NET 3.5 frameworks
  • LINQ is designed to fill the gap that exists between traditional .NET, that offers strong typing, and a full Object-Oriented approach
LINQ introduces an easy-learning approach for querying and modifying data and can support querying various types of data sources including relational data, XML and in-memory data structures.

Advantages of Using LINQ
LINQ offers the following advantages:
  1. LINQ offers a common syntax for querying any type of data sources
  2. Secondly, it binds the gap between relational and object-oriented approachs
  3. LINQ expedites development time by catching errors at compile time and includes IntelliSense & Debugging support
  4. LINQ expressions are Strongly Typed.

What we mean by Strongly Typed?
Strongly typed expressions ensure access to values as the correct type at compile time & prevents type mismatch errors being caught when the code is compiled rather at run-time.
Core Assemblies in LINQ
The core assemblies in LINQ are:
  1. using System.Linq
    Provides Classes & Interface to support LINQ Queries
  2. using System.Collections.Generic
    Allows the user to create Strongly Typed collections that provide type safety and performance (LINQ to Objects)
  3. using System.Data.Linq
    Provides the functionality to access relational databases (LINQ to SQL)
  4.  using System.Xml.Linq
     Provides the functionality for accessing XML documents using LINQ (LINQ to XML)
  5. using System.Data.Linq.Mapping
    Designates a class as an entity associated with a database.
Types of LINQ
LINQ provides three basic types of queries, each type offers specific functionality and is designed to query a specific source. The three basic types of queries are:
  1.  LINQ to Objects
  2. LINQ to XML(or XLINQ)
  3. LINQ to SQL(or DLINQ)
Let us briefly discuss each of them.
LINQ to Objects
  • LINQ to Object is the basics of LINQ
  • It enables us to perform complex query operations against any enumerable object (object that supports the IEnumerable interface)
LINQ queries provide the following advantages over traditional foreach loops:
  1. They are more concise & readable, especially when filtering multiple conditions
  2. Provides powerful filtering, grouping and ordering with little coding

Friday, 21 February 2014

how to convert number into words in C#



using System;

namespace ValueToWord
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(NumberToWord(2340567));
            Console.Read();
        }

        public static string NumberToWord(int Value)
        {
            if (Value == 0)
                return "zero";

            if (Value < 0)
                return "minus " + NumberToWord(Math.Abs(Value));

            string Output = "";

            if ((Value / 1000000) > 0)
            {
                Output += NumberToWord(Value / 1000000) + " million ";
                Value %= 1000000;
            }

            if ((Value / 1000) > 0)
            {
                Output += NumberToWord(Value / 1000) + " thousand ";
                Value %= 1000;
            }

            if ((Value / 100) > 0)
            {
                Output += NumberToWord(Value / 100) + " hundred ";
                Value %= 100;
            }

            if (Value > 0)
            {
                if (Output != "")
                    Output += "and ";

                dynamic WordList1 = new[] { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" };
                dynamic WordList2 = new[] { "zero", "ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" };

                if (Value < 20)
                    Output += WordList1[Value];
                else
                {
                    Output += WordList2[Value / 10];
                    if ((Value % 10) > 0)
                        Output += "-" + WordList1[Value % 10];
                }
            }

            return Output;
        }
    }
}

Output


Unsafe code using C#

Introduction

In unsafe code or in other words unmanaged code it is possible to declare and use pointers. But the question is why do we write unmanaged code? If we want to write code that interfaces with the operating system, or want to access memory mapped device or want to implement a time critical algorithm then the use of pointer can give lots of advantages.
But there are some disadvantages of using pointers too. If pointers were chosen to be 32 bit quantities at compile time, the code would be restricted to 4gig of address space, even if it were run on a 64 bit machine. If pointers were chosen at compile time to be 64 bits, the code could not be run on a 32 bit machine.
In C# we can write unsafe code with the modifier unsafe. All the unsafe code must be clearly marked with theunsafe modifier. Writing unsafe code is much like writing C code in a C# program.

Sample


using System;

class MyClass 
{
public static void Main() 
       {
unsafe 
               {
int i = 10;
int* p = &i;
Console.WriteLine("Value is " + i);
Console.WriteLine("Address is " + (int)p);
}
}
}

Output

Value is 10
Address is 1244316

Setting

To set this compiler option in the Visual Studio development environment

  1. Open the project's Properties page.
  2. Click the Build property page.
  3. Select the Allow Unsafe Code check box.



Thursday, 13 February 2014

How to Create our own permission Group in SharePoint 2010?



Step 1: Open Site

Step 2: Go to Site Action and Click Site Permission link.

Step 3: Click Permission Level Link Button.

Step 4: Click  Add a Permission Level

 







Step 5: Give Your own custom Permission Name

Step 6: Select the permissions to your custom permission level.


Step 7: Click Create Button.
Step 8: Click Site actions link after Click Site Permission 

Step 9: Click Create Group Icon 

Step 10: Follow  below screens



Wednesday, 12 February 2014

How to create every site individual content database sharepoint 2010

Step 1: Open CENTRAL Administration.
Step 2: Click "Manage web applications" Create a site


Step 3: Here created 4444 site.
Step 4: Click Manage content databases
Step 5: Click "Add a content database"


Step 6: click Ok.


Step 7: create site now first database is select first site and second site take site01 database.

Sunday, 9 February 2014

Build Automation in TFS 2010


This article demonstrates how to generate automated builds using Team Foundation Server and Team Builds.  

Step 1: Click Start Button
Step 2 : Select Team Foundation Administration Console.
Team Foundation Administration Console.



 
Step 3: Create a new collection.
Step 4: Here we can create Agents. 
Step 5: Every Agent is under the Team server


Step 6: Click Properties.
Open a Properties window    -> Here you will select “Build Controller Service is Enabled”
Next click OK button.


 
Step 7: Click Group Member.
Open a list of  Global Groups names are display.
Next
Step 8: Start MS-Visual Studio 2010.
Open Team Explorer.
Select Build
Go to  New Build Definition.


Step 9: General :
Name is Your Build Definitions name.
Description (optional). 
Step 10: When you want build that details are give here.
Step 11: Five kind of builds are available.
 

 
Step 12: status : mode set Active
Step 13: You give your Project path.
Step 14:Build Agent folder is $(sourceDir).

Step 15:Create a folder in C:\ that folder name
Step 16:\\temp\share.

 Next

 Build your Own Definition
Here you can give priority of your build

Your build is running Now
Your build is succeeded.  
Click Open Drop Folder (there your build version is save in this path).
My Server Path is: \\temp\share\Your Build Name\Your Build Name_20110811.8\_PublishedWebsites\AutoTFS



Your  build version folder


Team Foundation Server (TFS)

  • Microsoft product which offers source control, data collection, reporting, and project tracking
  • Intended for collaborative software development projects
  • Available either as stand-alone software, or as the server side back end platform for Visual Studio Team System (VSTS)

Team Build

  • Build server included with TFS
  • Can be used by developers to do a complete build of the most recent versions of the software contained in source control
  • Analyzes what changes have been made to in source control since the last successful build
  • Updates any work items to indicate that progress has been made