Showing posts with label LINQ. Show all posts
Showing posts with label LINQ. Show all posts

Tuesday, September 10, 2013

Interview Questions :- .NET,ASP.NET , SQL Server , C#, SharePoint, Javascript, Jquery

Hey All,
   Below are some Questions ( not answers :-) ) that are asked in interviews that I have faced. Hope they prove useful to you for your preparation at some point of time.

 The Questions are mixed of : ASP.NET , SQL Server , .NET Framework , SharePoint , C# , OOPS


  1. What are magic tables in SQL Server 
  2.  How many and what are temp tables in Sql Server ?
  3.  How will you call trigger in Sql Server ?
  4.  How will you call function in Sql Server ?
  5.   There are 2 tables A and B having 3 columns each...What is the output of " Select * from A,B?
  6.   What is the maximum number of Clustered indexes a table can have ?
  7.  when you update a table in SQL Server management studio .., what exactly happens ?
  8.  What is project life cycle?
  9.  What are the differences b/w SQL Server 2008 and SQL Server 2012?
  10.  What is the difference between Site Template and Site Definition?
  11.  What are Generics in C# ? What is the use of it ?
  12.  Protected vs Protected Internal in C# ?
  13.  can we create master page through sharepoint desginer ?
  14.  what is the difference between creating items through sharepoint designer and sharepoint server?
  15.  ASP.NET page life cycle?
  16.  when can we change page's Viewstate ? on which event ?
  17.  can you create site template ? how ?
  18.  what is the prurpose of SPSecurity class in SharePoint ?
  19.  what is Code access security in .NET ?
  20.  There are 2 tables A and B... A has 3 columns , 5 rows ... B has 2 columns , 3 rows ..What will be the output of  a) Select * from A,B b) cross join between 2 tables (how many rows and columns will a cross join between 2 tables return ?)
  21.  What are Cross joins ?
  22. how will update sharepoint list ? write the code.
  23.  what are extension methods in C#?
  24.  what are anonymous methods in c#?
  25.  why multiple inheritance is not possible in C#?
  26. what is a site column in SharePoint?
  27. Difference b/w sandboxed and Farm solution?
  28.  Difference b/w Web Parts and Visual Web Parts.
  29.  how to make a master page in Sharepoint Site?
  30.  abstract class vs interfaces
  31.   Explain Sharepoint Object Model
  32.  What are SPutility and SPMetal in SharePoint ?
  33.  What is .wsdl file in a web service ? 
  34.  how many ways you handle erors in a web page ?
  35.  HttpUtility class vs Http Module
  36.  Can you run JSP pages in IIS ? How ?
  37.  which exception will first occur ?inside BAL , DAL , or UI layers'?
  38.  What does theme in CSS contains ?
  39.  What are views in SQL Server ? can we perform DML in Views?
  40.  User Defined Functions Vs Stored Procedure?
  41.  Difference b/w SQL variable @ and @@
  42.  Difference between Hidden Field vs Viewstate ?
  43.  Boxing and Unboxing difference
  44. What are extension methods and extension classes in C#?
  45.  Inproc vs Outproc in Stored Procedures?
  46.  HTTP module vs HTTP handler
  47.  HTTP get vs HTTP Post?
  48. Abstraction vs Encapsulation
  49.  overloded methods can have different return type?
  50.  static class vs Sealed classes .. why are they used ?
  51.  polymorphism in C#
  52.  types of triggers in SQL SERVER
  53.  Left outer join in SQL SERVER
  54.  What are indexes in SQL SERVER
  55.  What are cursors in SQL Server
  56.  What is the new keyword in Method overriding?
  57.  What are different types of views in SQL Server?
  58.  what is a $ sign in Jquery ?
  59.  How will you enable a website to run only for indian country?
  60.  what are lambda expressions in C#?
  61.  what is difference between array and arraylist ? when to use what and which one is faster?
  62.  what is datareader ? how is it different from dataset?
  63.  What are out, ref parameter in C# method?
  64.  For vs ForEach loop
  65. what is the benefit of putting the .wsp or solution file inside GAC and inside BIN?
  66.  what is RunWithElevatedPrivileges in SharePoint?
  67.  what is the difference between webpart and Visual WebPart?
  68.  what is the difference between Sytem.web.UI.WebControls.Webparts.WebPart vs Microsoft.Sharepoint.WebPart?
  69.  Abstraction Vs Encapsulation
  70.  What is viewstate ? Can you store collections in Viewstate?
  71.  What is the difference between Stored Procedures and User Defined Functions in Sql Server ?
  72.  What is LINQ and advantages of LINQ ?
  73.  I have a collection of strings , Which will be more efficient LINQ or normal for / for each loop?
  74.  What are the ways of storing information into clients computers?
  75.  What are Selectors in Jquery ?
  76.  What are the advantages of Entity Framework?
  77.  Request vs Response Cycle of a Page?
  78. Limitations of sharepoint designer
  79. how will you create master pages and how will you deploy?
  80.  what is a feature ? how will you deploy feature?
  81.  how will you associate one content type to 3 lists ?
  82.  What is caching ? How many types of caching is there?
  83.  What is the difference between caching and session ?
  84.  Generic list vs arraylist vs array in terms of performance and why ?
  85.  why serialization is done and what are the types of serialization?
  86.  What is the difference b/w caching and Session ?
  87. Difference b/w httphandlers and http modules.
  88.  what are the limitations or disadvandtages of Generics
  89.  how to find the 4th highest salary in table?
  90.  .net 2.0 vs .net 4.0 features
  91.  What is garbage collector ?
  92.  garbage collector dispose vs finalize 
  93.  what are table valued functions in SQL Server
  94.  What are shared assemblies
  95.  What is Isnull and collasce operator in SQL Server?
  96.  interface vs abstract class
  97.  return server date in javascript 
  98.  how to increment each salary of all employees with 500 
  99.  how to work with cookies in asp.net 
  100.  javascript function on html control click and asp.net control click

    ALL THE VERY BEST !!!

Wednesday, November 23, 2011

Apply Custom Style to Gridview using Style class and ApplyStyle method

Hi,
  In this post I will apply my own style to the Gridview Control.


1) Add a new page say "GV.aspx" in your asp.net website/web application.


2) Drag and drop  Gridview and a button control from the toolbox on the page.


3) Bind the Gridview on page load event. I have used LINQ to SQL In this example for binding the Gridview.
 The database used is Northwind. The name of LINQ class here is DB and I have added two tables Product and Category.



DBDataContext db = new DBDataContext();
    protected void Page_Load(object sender, EventArgs e)
    {
        // Simple LINQ query
        var products = from p in db.Products
                       where p.Category.CategoryName == "Beverages"
                       select p;


        GridView1.DataSource = products;
        GridView1.DataBind();
    }

Note that I have instantiated DataContext class outside the Page Load event making it Global to the page.

4) Now I will create a new style from the Style class and apply it to the Gridview using ApplyStyle() method.On the button Click Event add this piece of code:

    protected void btnStyle_Click(object sender, EventArgs e)
    {
        Style myStyle = new Style();
        myStyle.ForeColor = System.Drawing.Color.Red;
        myStyle.BackColor = System.Drawing.Color.Turquoise;
        myStyle.Font.Bold = true;
        myStyle.BorderStyle = BorderStyle.Solid;
        GridView1.ApplyStyle(myStyle);
    }

5) Run it and click on the button and see the output.Below is the screenshot showing before and after applying style.

Gridview before applying style



Gridview after applying style (Click on Apply Style Button)



That's it..!

Thanks,
Nitin Sharma


Friday, April 9, 2010

Fetch Files with more than one extension from a Directory and Sorth them

Hi All,
There may be requirements in your project sometimes where you may fetch files of Particular extensions from a directory.
The Simple way for extension say " .docx " , the Directory search pattern works.

string[] fns = Directory.GetFiles(@"D:\Documents\", "*.docx*");

However if you want to search files of more than one type(extension), here is the way.

CODE:

var sort = from fn in fns

where fn.Contains(".jpg") || fn.Contains(".txt") || fn.Contains(".png")

orderby new FileInfo(fn).CreationTime descending

select fn;


I hope you know var keyword :p.(The anonymous types introduced in C# 3.0).

In the above example it gives the collection.

So at the end you get filtered all files from the directory/folder by just providing the extension name in file.contains() syntax like fn.Contains(".jpg")

Also note that the files can also be sorted(ascending/descending) by file Size,lastAccess,LastWrite,CreationTime.
In above example the files are sorted by CreationTime.

Thanks,
Nitin Sharma
Happy Coding

Monday, April 20, 2009

Querying Web.SiteMap using LINQ

Querying Web.SiteMap using LINQ

The sample web.sitemap used in this article is shown below:

xml version="1.0" encoding="utf-8"?>

<siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0">

<siteMapNode title="My Favorites">

<siteMapNode title="Favorite Sites">

<siteMapNode title="ASP.NET Home" url="http://www.asp.net" />

<siteMapNode title="ASP.NET Articles" url="http://www.dotnetcurry.com"/>

<siteMapNode title="Windows Client" url="http://www.windowsclient.net" />

<siteMapNode title="Silverlight" url="http://silverlight.net" />

siteMapNode>

<siteMapNode title="Favorite Blogs">

<siteMapNode title="ScottGu Blog" url="http://weblogs.asp.net/scottgu"/>

<siteMapNode title="Technology Blog" url="http://www.devcurry.com" />

<siteMapNode title="SQL Blog" url="http://www.sqlservercurry.com" />

<siteMapNode title="Food Lovers" url="http://foodatarian.com" />

siteMapNode>

<siteMapNode title="Favorite Social Sites">

<siteMapNode title="Twitter" url="http://twitter.com/"/>

<siteMapNode title="FaceBook" url="http://www.facebook.com" />

<siteMapNode title="LinkedIn" url="http://www.linkedin.com" />

<siteMapNode title="Orkut" url="http://www.orkut.com" />

siteMapNode>

siteMapNode>

siteMap>

The Data Source for above web.sitemap is Bulleted List.

<asp:BulletedList ID="linkList" DisplayMode="HyperLink" runat="server">

asp:BulletedList>

List all Url’s in the SiteMap using LINQ

XElement xelement = XElement.Load(Server.MapPath("~/web.sitemap"));

var urlList = xelement.Descendants().Attributes()

.Where(x => x.Name == "url")

.Select(x => x.Value);

foreach (string s in urlList)

{

linkList.Items.Add(s);

}

List Url’s and Title in the SiteMap using LINQ

XElement xelement1 = XElement.Load(Server.MapPath("~/web.sitemap"));

var urlDescList = xelement1.Descendants()

.Where(element => element.LastAttribute.Name.LocalName.Contains("url"))

.Select(nd => new

{

title = nd.Attribute("title")

.Value,

url = nd.Attribute("url")

.Value

});

foreach (var v in urlDescList)

{

ListItem li = new ListItem(v.title, v.url);

linkList.Items.Add(li);

}

List Url’s and Title of a particular node of the SiteMap using LINQ

XElement xelement2 = XElement.Load(Server.MapPath("~/web.sitemap"));

var urlDescList1 = xelement2.Descendants()

// Select node with 'Favorite Social Sites'

.Where(sel => (string)sel.Attribute("title") == "Favorite Social Sites")

.SelectMany(sel => sel.Elements())

.Select(nd => new

{

title = nd.Attribute("title").Value,

url = nd.Attribute("url").Value

});

foreach (var s in urlDescList1)

{

ListItem li = new ListItem(s.title, s.url);

linkList.Items.Add(li);

}

Count the number of nodes in each parent element of SiteMap using LINQ

XElement xelement3 = XElement.Load(Server.MapPath("~/web.sitemap"));

var t = xelement3.Descendants()

.Where(x => x.LastAttribute.Name.LocalName != "url")

.Select(ele => new

{

Name = (string)ele.Attribute("title"),

Count = ele.Elements().Count()

});

Source: http://www.dotnetcurry.com/ShowArticle.aspx?ID=284&AspxAutoDetectCookieSupport=1

Thanks,

Nitin Sharma

Monday, March 9, 2009

Multiple Joins in LINQ



Hi All,
This Post will show how to implement multiple Joins in LINQ.



using System;

using System.Collections;

using System.Configuration;

using System.Data;

using System.Linq;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.HtmlControls;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Xml.Linq;

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

{

DemoDataContext DC = new DemoDataContext();

protected void Page_Load(object sender, EventArgs e)

{

if (!IsPostBack)

{

Bind();

}

}

private void Bind()

{

// How to Apply Joins in LINQ

var items = from P in DC.Emps

join Ep in DC.EmpProducts on P.SINo equals Ep.SINo

join TT in DC.TextTables on P.SINo equals TT.SINo

select new

{

Name = P.Name,

Age = P.Age,

Country = P.Country,

State = P.State

};

GVInJoins.DataSource = items;

GVInJoins.DataBind();

}

}


On Debugging the Query we will find it like as........



{SELECT [t0].[Name], [t0].[Age], [t0].[Country], [t0].[State]
FROM [dbo].[Emp] AS [t0]
INNER JOIN [dbo].[EmpProduct] AS [t1] ON [t0].[SINo] = [t1].[SINo]
INNER JOIN [dbo].[TextTable] AS [t2] ON [t0].[SINo] = [t2].[SINo]
}




Now finally Bind the Output to the Gridview and its ready now...




Thanks to LINQ :)


Thanks,

Nitin Sharma