Wednesday 29 April 2015

SharePoint 2013 Concepts

Backup and Restore
BCS
CAML and LINQ
Content Management
Content Type
Downloads
Errors
Event Receivers
Installation
Interview Questions
JavaScript and jQuery
List and Library
Master Page and Page Layout
Mobile apps
New Features
PowerShell
Product Reviews
SharePoint 2013
SharePoint 2013 Apps
SharePoint 2013 InfoPath
SharePoint 2013 object model
SharePoint 2013 Security
SharePoint Customization
SharePoint Designer 2013
SharePoint Online
SharePoint Search
Site Collections
Site Templates and Site Definition
Video Tutorials
Visual Studio 2012
Web Part
Workflow
Active Directory

Wednesday 26 November 2014

How to get data from db and store in array list and diplay it using foreach loop

  1. SqlConnection con = new SqlConnection("Data Source=XXXXX;Initial Catalog=XXXXX;Persist Security Info=True;User ID=XXXXX;Password=XXXXX");
  2. SqlCommand cmd = new SqlCommand();
  3. cmd.CommandText = ("Select * from Employee");
  4. cmd.Connection = con;
  5. try
  6. {
  7. con.Open();
  8. SqlDataReader dr = cmd.ExecuteReader();
  9. ArrayList Al = new ArrayList();
  10. if (dr.HasRows)
  11. {
  12. while (dr.Read())
  13. {
  14. Al.Add(dr.GetInt32(0) + " , " + dr.GetString(1) + "," + dr.GetDateTime(2) + "," + dr.GetString(3));
  15. }
  16. }
  17. dataGridView1.DataSource = Al;
  18. }
  19. finally
  20. {
  21. con.Close();
  22. }

How to finding duplicate elements in array

  1. var counts = new Dictionary<int, int>();
  2. int[] array = { 10, 5, 10, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 11, 12, 12 };
  3. for (int i = 0; i < array.Length; i++)
  4. {
  5. int currentVal = array[i];
  6. if (counts.ContainsKey(currentVal))
  7. counts[currentVal]++;
  8. else
  9. counts[currentVal] = 1;
  10. }
  11. foreach (var kvp in counts)
  12. MessageBox.Show("\t\n " + kvp.Key + " occurs " + kvp.Value);

Friday 14 November 2014

Visual Studio 2015 Preview

Top feature highlights of Visual Studio 2015 Preview include:

·         Ability to create ASP.NET 5 websites that can run on multiple platforms, including Windows, Mac, and Linux
·         Integrated support for building apps that run across Android, iOS, and Windows devices with integration of Visual Studio Tools for Apache Cordova (including new iOS debugging and seamless integration with TypeScript) as well as new Visual C++ tools for cross-platform library development
·         Connected Services manager that lets developers discover and consume REST APIs in their applications, including support for Azure Mobile Services, Azure Store, Office 365, and Salesforce
·         Smart Unit Tests (based on the PEX technology developed by Microsoft Research) that analyze code and automatically generate unit tests to describe its behavior
·         New coding productivity capabilities, particularly for C# and VB, built-in integration of the new “Roslyn” .NET compiler platform
·         New language features in C# 6 to reduce boilerplate and clutter in everyday code, and new light bulbs in the editor that bring proactive refactoring and code fixing opportunities
·         Support for breakpoint configuration and PerfTips, both available directly in context in the editor
·         Edit and debug a single set of C++ source code and build it for Android, iOS, and Windows; integrated support for the Clang complier and LLVM optimizer for targeting Android now and iOS “soon”

·         More complete C++ 11 and C++ 14 support, as well as dozens of additional productivity features for C++ developers, including new refactorings, improved “Find in Files,” a Memory Diagnostics tool, and improved incremental builds

Wednesday 5 November 2014

What is Caching



It’s nothing but a thought kind of memory. In respect to asp.net it's the memory of the machine/server from where the source-code is running. It is the one way which allows storing complex data for reusability.

Now think criteria where clients access an ASP.NET page, there are basically two ways to provide them with the information they need:

· The ASP.NET page can either obtain information from server resources, such as from data that has been persisted to a database, or
· the ASP.NET page can obtain information from within the application.

Retrieving information from a resource outside the application will require more processing steps, and will therefore require more time and resources on the server than if the information can be obtained from within the application space.

Now, suppose the information's which sent to browsers have already been prepared then how faster the process of web-page.

The ASP.NET 3.5 Framework supports the following types of caching:

Page Output Caching:

Page Output Caching caches an entire page. 

Partial Page Caching:

Partial Page Caching enables you to get around this problem by enabling you to cache only particular regions of a page.

DataSource Caching:

You use DataSource Caching with the different ASP.NET DataSource controls such as the SqlDataSource and ObjectDataSource controls. When you enable caching with a DataSource control, the DataSource control caches the data that it represents.

Data Caching:

Finally, Data Caching is the fundamental caching mechanism. Behind the scenes, all the other types of caching use Data Caching. You can use Data Caching to cache arbitrary objects in memory. For example, you can use Data Caching to cache a Dataset across multiple pages in a web application.

Note:
The Cache object can also have an expiration which would allow us to reinstitute data into the memory in intervals. Using the same example as above, we can make the cache expire every two hours, and repopulate the data. It would do this every 2 hours throughout the day, allowing the most up to date data to be fetched. Below is an example of how something can be put into the cache:

Referenced from msdn 

http://msdn.microsoft.com/en-us/library/system.web.caching.cache(VS.80).aspx

public void AddItemToCache(Object sender, EventArgs e)
{
itemRemoved = false;
onRemove = new CacheItemRemovedCallback(this.RemovedCallback);
if (Cache["Key1"] == null)
Cache.Add("Key1", "Value 1", null, DateTime.Now.AddSeconds(60),TimeSpan.Zero, CacheItemPriority.High, onRemove);
}


public void RemoveItemFromCache(Object sender, EventArgs e)
{
if(Cache["Key1"] != null)
Cache.Remove("Key1");
}

What is ASP.NET State Management? How to manage state in ASP.NET?


State management is used to keep values across post back event occurs.

There are two types of state management are available in the ASP.NET.

1) Client based State management

2) Server based State management

Client based state management

Here I am going to explain about in detail about client based state management.

1) What is View State?

View state is nothing but it is used to store the value across post back in the same page, Mean if you store the value in the Default.aspx page then that value is accessible only within the same Default.aspx page not able to call in the other pages like Default2.aspx etc.

Advantages:

Simple for a page level data

Possible to Encrypted

Can be set at the control level.

Disadvantage:

Overhead in encoding View State Values.

Makes a page heavy

View State Example

Client side


Enter Your Name <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Submit" onclick="Button1_Click" /><br />
<asp:Label ID="lblmsg" runat="server"></asp:Label>

Code behind


protected void Button1_Click(object sender, EventArgs e)
{
    //Declare value in the View State
    ViewState["key"] = TextBox1.Text;

    //check view state have value using if loop before assign value
    if (ViewState["key"] != null && ViewState["key"].ToString() != "")
    {
        //Get value from view state like below
        lblmsg.Text = ViewState["key"].ToString();
    }

    //Remove View state value like this
    ViewState["key"] = null;
}


2) What is Hidden field?

Hidden file is also client based state management control. It is keep the value across post back Refer below code sample for that. Hidden fields are also used to store data at the page level.

Advantages:

Simple to implement for a page specific data.

Can store small amount of data so they take less size.

Disadvantage:

Inappropriate for sensitive data.

Hidden Field value can be intercepted (clearly Visible) when over the network.

Hidden Field Example

Client side


Enter Name
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" /><br />
<asp:Label ID="lblmsg" runat="server"></asp:Label>
<asp:HiddenField ID="HiddenField1" runat="server" />

Code behind


protected void Button1_Click(object sender, EventArgs e)
    {
        //Assign value in hidden field like below
        HiddenField1.Value = TextBox1.Text;
       
        //Get the value from hidden field like below
        lblmsg.Text = HiddenField1.Value;
    }


3) What is Cookie?

A Cookie is a small piece of data stored on the user's computer. Most browsers allow only 20 cookies per site

Advantages:

Simplicity easy to create and use in web page.

Disadvantages:


Cookies functionality may be disabled on Users Browsers, so make sure before using this.

Cookies are transmitted for each HTTP request/response causing over head on bandwidth.

Cookies are Inappropriate for sensitive data like banking applications etc.


Cookie Example



protected void Button1_Click(object sender, EventArgs e)
{
    //Add cookies with key and name in the user's browsers
    Response.Cookies["UserId"].Value = TextBox1.Text;

    //Get back value from cookies and assign in the label control
    lblmsg.Text = Request.Cookies["UserId"].Value.ToString();
}


4) What is Query string?

Query String is usually used to send information from one page to another page. They are passed along with URL in clear text and also encrypted text passed through url.

Advantages:

Simple for to implement.

Disadvantage:

Human Readable unless you are not encrypt text before passing to query string.

Client Browser limit on URL length.

Cross paging functionality makes it redundant.

Easily modified by end user at run time if query string not encrypt.

Query String Example

Example

Page1.aspx Client side


Enter Name
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />

Page1.aspx.cs Code behind


protected void Button1_Click(object sender, EventArgs e)
{
    //Get the text box value and pass that value in to other page using query string
    Response.Redirect("04QryString2.aspx?name=" + TextBox1.Text);
}

Page2.aspx.cs

In the second page get that query string value and bind in the label like below


protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        Label1.Text = Request.QueryString["name"].ToString();
    }
}




Server based state management

Here I am going to explain about in detail about server based state management. Here all this values are store in the server not in user client side.


1) What is Session?

Session is used to keep values across post back and keep values across all pages too, mean if you declare value in the session variable you can call that session value in any page of the project. Compare to other View state, hidden Field etc. Session have most popular state management control.

Session Example

Page1.aspx Client side


Enter Name
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /><br />

Page1.aspx.cs Code Behind


protected void Button1_Click(object sender, EventArgs e)
{
    //initialize session value like below
    Session["name"] = TextBox1.Text;
    Response.Redirect("05Session2.aspx");
}

Page2.aspx Client side


<asp:Label ID="lblmsg" runat="server" Text="Label"></asp:Label>


Page2.aspx.cs Code Behind


protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        //Check before bind session have value
        if (Session["name"] != null)
        {
            lblmsg.Text = Session["name"].ToString();
        }

        //Remove particular session and its value
        Session.Remove("name");

        //Remove all session in the project like below
        Session.RemoveAll();
    }
}


2) What is Cache?

Cache is also used to keep values in the server. It is not like session, it is application oriented control.


Cache Example

Code behind

protected void Button1_Click(object sender, EventArgs e)
    {
        //Create cache like below
        Cache["t1"] = TextBox1.Text;

        //Get value from cache below
        Label1.Text = Cache["t1"].ToString();

        //Remove cache and its value like below
        Cache.Remove("t1");

    }



Tuesday 4 November 2014

sql query interview questions

Write query to get all employee detail from "EmployeeDetail" table?

SELECT * FROM [EmployeeDetail]


Write query to get only "FirstName" column from "EmployeeDetail" table?

SELECT FirstName FROM [EmployeeDetail]


Write query to get FirstName in uppler case as "First Name"?

SELECT UPPER(FirstName) AS [First Name]  FROM [EmployeeDetail]


Write query to get FirstName in lower case as "First Name"?

SELECT LOWER(FirstName) AS [First Name]  FROM [EmployeeDetail]


Write query for combine FirstName and LastName and display it as "Name" (also include white space between first name & last name)?

SELECT FirstName +' '+ LastName AS [Name]  FROM [EmployeeDetail]


Select employee detail whose name is "Vikas"?

SELECT * FROM [EmployeeDetail] WHERE FirstName = 'Vikas'


Get all employee detail from EmployeeDetail table whose "FirstName" start with latter 'a'?

SELECT * FROM [EmployeeDetail] WHERE FirstName like 'a%'



Get all employee details from EmployeeDetail table whose "FirstName" contains 'k'?

 SELECT * FROM [EmployeeDetail] WHERE FirstName like '%k%'



Get all employee details from EmployeeDetail table whose "FirstName" end with 'h'?

 SELECT * FROM [EmployeeDetail] WHERE FirstName like '%h'

  
Get all employee detail from EmployeeDetail table whose "FirstName" start with any single character between 'a-p'?

 SELECT * FROM [EmployeeDetail] WHERE FirstName like '[a-p]%'

Get all employee detail from EmployeeDetail table whose "FirstName" not start with any single character between 'a-p'?

SELECT * FROM [EmployeeDetail] WHERE FirstName like '[^a-p]%'


Get all employee detail from EmployeeDetail table whose "Gender" end with 'le' and contain 4 letters.--The Underscore(_) Wildcard Character represents any single character?

SELECT * FROM [EmployeeDetail] WHERE Gender like '__le' --there are two "_"


Get all employee detail from EmployeeDetail table whose "FirstName" start with 'A' and contain 5 letters?


SELECT * FROM [EmployeeDetail] WHERE FirstName like 'A____' --there are two "_"

Get all employee detail from EmployeeDetail table whose "FirstName" containing '%'. ex:-"Vik%as"?

SELECT * FROM [EmployeeDetail] WHERE FirstName like '%[%]%' --there are two "_"
--According to our table it would return 0 rows, because no name containg '%'


Get all unique "Department" from EmployeeDetail table.

SELECT DISTINCT(Department) FROM [EmployeeDetail]


Get the highest "Salary" from EmployeeDetail table.

SELECT MAX(Salary) FROM [EmployeeDetail]


Get the lowest "Salary" from EmployeeDetail table.

SELECT MIN(Salary) FROM [EmployeeDetail]

Show "JoiningDate" in "dd mmm yyyy" format, ex- "15 Feb 2013"

SELECT CONVERT(VARCHAR(20),JoiningDate,106) FROM [EmployeeDetail]

Show "JoiningDate" in "yyyy/mm/dd" format, ex- "2013/02/15"
SELECT CONVERT(VARCHAR(20),JoiningDate,111) FROM [EmployeeDetail]

Show only time part of the "JoiningDate".

SELECT CONVERT(VARCHAR(20),JoiningDate,108) FROM [EmployeeDetail]


Get only Year part of "JoiningDate".

SELECT DATEPART(YEAR, JoiningDate) FROM [EmployeeDetail] 


Get only Month part of "JoiningDate".

SELECT DATEPART(MONTH,JoiningDate) FROM [EmployeeDetail]

Get system date.

SELECT GETDATE()

Get UTC date.

SELECT GETUTCDATE()

Get the first name, current date, joiningdate and diff between current date and joining date in months.

SELECT FirstName, GETDATE() [Current Date], JoiningDate,
DATEDIFF(MM,JoiningDate,GETDATE()) AS [Total Months] FROM [EmployeeDetail]

Get the first name, current date, joiningdate and diff between current date and joining date in days.

SELECT FirstName, GETDATE() [Current Date], JoiningDate,
DATEDIFF(DD,JoiningDate,GETDATE()) AS [Total Months] FROM [EmployeeDetail]


Get all employee details from EmployeeDetail table whose joining year is 2013.

SELECT * FROM [EmployeeDetail] WHERE DATEPART(YYYY,JoiningDate) = '2013'

Get all employee details from EmployeeDetail table whose joining month is Jan(1).

SELECT * FROM [EmployeeDetail] WHERE DATEPART(MM,JoiningDate) = '1'

Get all employee details from EmployeeDetail table whose joining date between "2013-01-01" and "2013-12-01".

SELECT * FROM [EmployeeDetail] WHERE JoiningDate BETWEEN '2013-01-01' AND '2013-12-01'

Get how many employee exist in "EmployeeDetail" table.

SELECT COUNT(*) FROM [EmployeeDetail]

Select only one/top 1 record from "EmployeeDetail" table.

SELECT TOP 1 * FROM [EmployeeDetail]


Select all employee detail with First name "Vikas","Ashish", and "Nikhil".

SELECT * FROM [EmployeeDetail] WHERE FirstName IN('Vikas','Ashish','Nikhil')


Select all employee detail with First name not "Vikas","Ashish", and "Nikhil".

SELECT * FROM [EmployeeDetail] WHERE FirstName NOT IN('Vikas','Ashish','Nikhil')


Select first name from "EmployeeDetail" table after removing white spaces from right side

SELECT RTRIM(FirstName) AS [FirstName] FROM [EmployeeDetail]


Select first name from "EmployeeDetail" table after removing white spaces from left side

SELECT LTRIM(FirstName) AS [FirstName] FROM [EmployeeDetail]



Display first name and Gender as M/F.(if male then M, if Female then F)

SELECT FirstName, CASE  WHEN Gender = 'Male' THEN 'M'
WHEN Gender = 'Female' THEN 'F'
END AS [Gender]
FROM [EmployeeDetail]

Select first name from "EmployeeDetail" table prifixed with "Hello "

SELECT 'Hello ' + FirstName FROM [EmployeeDetail]

Get employee details from "EmployeeDetail" table whose Salary greater than 600000

SELECT * FROM [EmployeeDetail] WHERE Salary > 600000

Get employee details from "EmployeeDetail" table whose Salary less than 700000

SELECT * FROM [EmployeeDetail] WHERE Salary < 700000


Get employee details from "EmployeeDetail" table whose Salary between 500000 than 600000

SELECT * FROM [EmployeeDetail] WHERE Salary BETWEEN 500000 AND 600000


Select second highest salary from "EmployeeDetail" table.

SELECT TOP 1 Salary FROM
(
      SELECT TOP 2 Salary FROM [EmployeeDetail] ORDER BY Salary DESC
) T ORDER BY Salary ASC



Write the query to get the department and department wise total(sum) salary from "EmployeeDetail" table.

SELECT Department, SUM(Salary) AS [Total Salary] FROM [EmployeeDetail]
GROUP BY Department

Write the query to get the department and department wise total(sum) salary, display it in ascending order according to salary.

SELECT Department, SUM(Salary) AS [Total Salary] FROM [EmployeeDetail]
GROUP BY Department ORDER BY SUM(Salary) ASC

Write the query to get the department and department wise total(sum) salary, display it in descending order according to salary.

SELECT Department, SUM(Salary) AS [Total Salary] FROM [EmployeeDetail]
GROUP BY Department ORDER BY SUM(Salary) DESC
  
Write the query to get the department, total no. of departments, total(sum) salary with respect to department from "EmployeeDetail" table.

SELECT Department, COUNT(*) AS [Dept Counts], SUM(Salary) AS [Total Salary] FROM [EmployeeDetail]
GROUP BY Department

Get department wise average salary from "EmployeeDetail" table order by salary ascending
  
SELECT Department, AVG(Salary) AS [Average Salary] FROM [EmployeeDetail]
GROUP BY Department ORDER BY AVG(Salary) ASC


Get department wise maximum salary from "EmployeeDetail" table order by salary ascending
  
SELECT Department, MAX(Salary) AS [Average Salary] FROM [EmployeeDetail]
GROUP BY Department ORDER BY MAX(Salary) ASC



Get department wise minimum salary from "EmployeeDetail" table order by salary ascending

SELECT Department, MIN(Salary) AS [Average Salary] FROM [EmployeeDetail]
GROUP BY Department ORDER BY MIN(Salary) ASC


Write down the query to fetch Project name assign to more than one Employee

Select ProjectName,Count(*) [NoofEmp] from [ProjectDetail] GROUP BY ProjectName HAVING COUNT(*)>1


Get employee name, project name order by firstname from "EmployeeDetail" and "ProjectDetail" for those employee which have assigned project already.

SELECT FirstName,ProjectName FROM [EmployeeDetail] A INNER JOIN [ProjectDetail] B
ON A.EmployeeID = B.EmployeeDetailID ORDER BY FirstName


Get employee name, project name order by firstname from "EmployeeDetail" and "ProjectDetail" for all employee even they have not assigned project.

SELECT FirstName,ProjectName FROM [EmployeeDetail] A LEFT OUTER JOIN [ProjectDetail] B
ON A.EmployeeID = B.EmployeeDetailID ORDER BY FirstName

Get employee name, project name order by firstname from "EmployeeDetail" and "ProjectDetail" for all employee if project is not assigned then display "-No Project Assigned".

SELECT FirstName, ISNULL(ProjectName,'-No Project Assigned') FROM [EmployeeDetail] A LEFT OUTER JOIN [ProjectDetail] B
ON A.EmployeeID = B.EmployeeDetailID ORDER BY FirstName

Get all project name even they have not matching any employeeid, in left table, order by firstname from "EmployeeDetail" and "ProjectDetail".

SELECT FirstName,ProjectName FROM [EmployeeDetail] A RIGHT OUTER JOIN [ProjectDetail] B
ON A.EmployeeID = B.EmployeeDetailID ORDER BY FirstName


Get complete record(employeename, project name) from both tables([EmployeeDetail],[ProjectDetail]), if no match found in any table then show NULL.

SELECT FirstName,ProjectName FROM [EmployeeDetail] A FULL OUTER JOIN [ProjectDetail] B
ON A.EmployeeID = B.EmployeeDetailID ORDER BY FirstName


Write a query to find out the employeename who has not assigned any project, and display "-No Project Assigned"( tables :- [EmployeeDetail],[ProjectDetail]).

SELECT FirstName, ISNULL(ProjectName,'-No Project Assigned') AS [ProjectName] FROM [EmployeeDetail] A LEFT OUTER JOIN [ProjectDetail] B
ON A.EmployeeID = B.EmployeeDetailID
WHERE ProjectName IS NULL


Write a query to find out the project name which is not assigned to any employee( tables :- [EmployeeDetail],[ProjectDetail]).

SELECT ProjectName FROM [EmployeeDetail] A RIGHT OUTER JOIN [ProjectDetail] B
ON A.EmployeeID = B.EmployeeDetailID
WHERE FirstName IS NULL

Write down the query to fetch EmployeeName & Project who has assign more than one project.

Select EmployeeID, FirstName, ProjectName from [EmployeeDetail] E INNER JOIN [ProjectDetail] P
ON E.EmployeeID = P.EmployeeDetailID
WHERE EmployeeID IN (SELECT EmployeeDetailID FROM [ProjectDetail] GROUP BY EmployeeDetailID HAVING COUNT(*) >1 )

Write down the query to fetch ProjectName on which more than one employee are working along with EmployeeName.

Select FirstName, ProjectName from [EmployeeDetail] E INNER JOIN [ProjectDetail] P
ON E.EmployeeID = P.EmployeeDetailID