Showing posts from 2015

Improve ASP.Net Website performance using PageAdapter

If you are working on a website then there might be a chance to handle large amount of data on a public site.

Generally we are binding code with Gridview like this:

Gridview1.Datasource = dataset;

All about Active Directory Programming in C#

Active Directory is a central database for your organization. It keeps record in various domain.
This is a Directory structure used in Windows operating system to store information related to networks and domains within organization. Active Directory was first introduced in Windows 2000.  Active Directory is a hierarchical structure which helps organization in organizing information.

All about sp_addlinkedserver syntax

sp_addlinkedserver linked 2 servers. Once sp_addlinkedserver query executes, query can be run against these servers.Run below queries one by one to link, to provide login credentials and to access data
EXEC sp_addlinkedserver @server='ServerName' EXEC sp_addlinkedsrvlogin 'ServerName', 'false', NULL, 'username', 'password' select * from [ServerName].[DBName].[DBO].[TableName]
Once your requirement is done, you may drop the linking by running following query. EXEC sp_dropserver 'ServerName', 'droplogins'

Client Side Pagination in Gridview

As you know pagination is very important for any data control for eg Gridview if you have large amount of data. Server load on pagination is also a big concern.
Below is the code for pagination in gridview using client side. It means no page load/ server post back operation will be performed.

HTML Form Validations

Form validation for Alphabet only:

Sometimes you may require to allow only alphabet in a particular input field. For Eg first name and last name field should not allow any other character apart from alphabet.

How to access SharePoint List with List Web Service

SharePoint List Web service allow developers to access, manipulate List and List items through a service url.
Generally List web service url format is : http://site/_vti_bin/lists.asmx
Now lest start consuming this service and manage SharePoint List. Open this url: http://spsite:1985/_vti_bin/lists.asmx Open Visual Studio 2010. Right click on project and add service reference.
Then click on Advanced… (Refer below screen shot)

Bind Drop-down with SharePoint List and display list items in a Gridview

In this blog, I will explain about below point through C# code:
1. Bind all list in a dropdown
2 Load List items in a Gridview once a user changes list name in dropdown.

You need to create a visual webpart in Visual studio 2010.

Difference between Stored Procedure and Function in SQL

All about Managed Metadata Services in SharePoint 2010

What is Metadata?Metadata is data about data i.e. information about some object. Managed Metadata Service is a feature of enterprise content management. Managed metadata allows same content type to be used across multiple site collection, this is called content type hub.

Configure FBA (Form Based Authentication) in SharePoint 2010

Go to %windir%\Microsoft.Net\Framework64\v2.0.50727 , and run aspnet_regsql.exe

How to create site definition in SharePoint 2010

How to create site definition in SharePoint 2010?Let's start this blog by understanding the difference between Site Definition and Site Template.
Site Template is a ready made layout that we can use to create a site. It has pre-defined top nav, quick launch, list etc.

SharePoint Interview Questions and Answers

If you have landed to this page it means you are searching for SharePoint Interview Questions and answers, right? You are at right place. In this blog, I have collected important SharePoint interview questions and answers.
Candidate having good knowledge of SharePoint will shine like a star in IT industry. So, it is very important to collect more and more SharePoint interview Questions and Answers to qualify SharePoint interview. Below are few SharePoint questions and answers which are very important and most of them were asked in an interview in IT Companies.

Important C# Interview Questions and Answers

Hi all, I am sharing few important questions and answers of c# asked in the interview.
Most popular interview Questions and Answers in C# Programming

Why we use Cookie?

What is Cookies? Cookies here refer as Web Cookies, HTTP Cookies is a small piece of code stored at user's machine by bowers.

Java Script Form Validation- ASP.Net Web Form

Java Script is the best way to validate a web form at client side and ensure the most accurate data to store from an HTML or web forms.

In this blog, I will explain about all kind of validation that is used in an ASP.Net and HTML forms

ASP.Net Interview Questions and Answers

In this blog, I have collected few ASP.Net interview questions and answers.

PowerShell Command List used in SharePoint 2010

PowerShell Command which are common in use for a SharePoint Developer.

Backup-SPSite http://oldsite -Path C:\backup\sitename.bak

Restore-SPSite http://newsite -Path C:\backup\sitename.bak

Add-SPsolution "C:\File1.wsp"

Update WSP
Update-SpSolution -Identity File1.wsp -LiteralPath "C:\File1.wsp" -GACDeployment

Install WSP
Install-SPSolution -Identity "File.wsp"  -WebApplication "http://siteurl"

Enable-SPFeature -identity "MyFeature" -URL "http://siteurl"

Disable Feature
Disable-SPFeature -identity "MyFeature" -URL "http://siteurl"

Install-SPFeature -path "MySPFeature1"

Uninstall Feature
Uninstall-SPFeature -Identity "MySPFeature1"

Get Farm ID

How to create a secure webservice in

Web service is a way to communicate between 2 machines via http, those 2 machines can be on different platform.
See more about web service at this url :

As you know web service is a way to communicate over http, so the main concern here is security.
What are the possibilities and ways to make a secure web service.

Below are few authentication options that are available to web service in ASP.Net

Windows BasicWindows Basic Over SSLWindows Client CertificatesCustom SOAP Headers In this blog I will explain about how can we secure web service using Custom SOAP Header.
SOAP web service includes following items it it. SOAP Envelop, SOAP Header, SOAP Body, SOAP Fault
Lets implement Custom SOAP Header by an example.
Create a Web Project in Visual Studio, Add web service in your project.
Write Below code:

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Script.Serialization; u…

Throttling and Indexing in SharePoint List

Throttling and Indexing in SharePoint List

In SharePoint, List is like a table with rows and columns.Similar to SQL tables SharePoint List need indexing if contains heavy amount of data else it will degrade the performance of SharePoint application.

So what is indexing?
Indexing in SharePoint list is similar to indexing in SQL database, but in SharePoint list indexing is maintained by SharePoint and not by SQL.

Indexing columns in a SharePoint List will improve the performance. A SharePoint List support maximum 20 indices. And also remember that not all column data types can be indexed.

Now we will move to Query Throttling.
Query throttling is a new feature in SharePoint 2010. It limits the list items that will be accessed in a single request. By default its limit is 5000 for users and 20,000 for SharePoint Admin.

List View Threshold can be overridden by using below property.

To manage Query throttling settings you can use SPList.EnableThrottling.
Click Here to kno…

Resource Throttling Setting unable to open, Error message is Updates are currently disallowed on GET requests.

Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb.

I searched on google and found the solution.
You need to update webapplication throttle setting through powershell command

$w = get-spwebapplication http://mysite:2015

List Threshold setting page should open now.

What is QueryThrottleMode in SPQuery Class?

As per MSDN definition, QueryThrottleMode is a property of SPQuery class which gets or sets value that indicate the throttling mode to be applied to the query.

As we know that List Throttling is a new option available in SharePoint 2010. List Throttling limits the list data that will be fetched in a single request.
Beyond the limit, request will not be allowed.

 ListView Threshold limit can be set through Central Admin and is applicable for web application that will be selected.

QueryThrottleMode property can be used with SPQuery and SPSiteDataQuery  object as shown in below code.

SPList spList = spWeb.Lists["mylist"];
                SPQuery spQuery = new SPQuery(spList .DefaultView);
                spQuery.QueryThrottleMode = SPQueryThrottleOption.Override;

QueryThrottleMode has 3 enum values:
Default - 0
Override - 1
Strict - 2

Logging to ULS in SharePoint 2010.

ULS stands for Unified Logging Service
ULS helps developer to avoid debugging code again and again to find out bugs.
ULS clearly specifies the error in details.
Generally SharePoint logs can be found at hive folder i.e. \14\LOGS
But this log file is not an easy task to read and understand.

To make it easy you should use tools like ULS viewer.
Download ULS viewer to read logs.

To write log in ULS need to write below code.

Please add 2 namespace:

using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

protected void btnUpdate_Click(object sender, EventArgs e)
                using (SPSite site = new SPSite("http://myspsite:1985"))
                    using (SPWeb web = site.OpenWeb())
                        SPList list = web.Lists["mylist1"];
                        SPListItemCollection items = list.GetItems();
                        web.AllowUnsafeUpdates = true;

What is delegate control? Why to use it?

Delegate control allow developers to manage control on master page without touching or editing master page.

Actually delegate control is associated with a feature. Whenever that feature is active delegate control will be visible and if associated feature is de-active delegate control will not be visible to users.

Lets implement this by an example.
To do this, create a SharePoint project in Visual Studio 2010.
Add an user control and a module in your project.

Now your project hierarchy should look like this.

Write below line of code in UserControl1.ascx

 <h1>This is my Delegate Control Demo</h1> 

Now open Element.xml file under Module1.

Remove code between <Elements> ......</Elements> tags
So your new Elements.xml file should look like this.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
  <Control Id="mytest" Sequence="1000" ControlSrc="~/_cont…

The method "GetItems" of the type "List" with id "{Guid}" is blocked by the administrator on the server.

I was working on SharePoint Client Context, and i was writing a piece of code to fetch items from SharePoint list.

I got this error at this line:

I solved this issue by executing powershell command.
Open SharePoint Powershell  and type below command one by one.

$webapp = Get-SPWebApplication "http://spserver"$webapp.ClientCallableSettings.AnonymousRestrictedTypes.Remove([microsoft.sharepoint.splist], "GetItems")$webapp.Update()Open SharePoint Powershell  and type below command one by one.Now run your code, you can now access SharePoint List Data.

Powershell Command to add a file to root of SharePoint

This blog will explain about adding a file to SharePoint root.
Generally sharepoint structure is http://server/pages/page1.html
Suppose you need to add a file in root which should access by http://server/page1.html

This can be done by powershell command.

Write-Host "Powershell started....."
Add-PSSnapIn Microsoft.SharePoint.PowerShell
$fileBytes = []::ReadAllBytes("C:\myfolder\page1.html");
$site = Get-SPSite "http://server";
$site.RootWeb.Files.Add("page1.html", $fileBytes, $true);
Write-Host "Done..."

Create SharePoint List with Code and CAML

CAML is an XML based language used for access SharePoint objects like List, Library, Content Type, Site Columns.

To know more about CAML Query, please visit my another blog post Learn CAML Query step by Step
CAML comes under declarative and the code that we write using SharePoint server object model comes under imperative programming.

Interview Questions and Answer in ASP.Net

The ASP.Net Questions and Answers available in this blog are helpful for beginners as well as for experienced developers.

Below are the most important interview questions and answers.

Linq in C# Programming

Before using LINQ in C#, please read my earlier blog to get some basic idea about what is LINQ?

LINQ can be used in C# in different ways :

One way is to use with Lambda Expression
Another way is to use Anonymous function

Below code will return string of length less than 5.

string[] countryArr = { "India", "USA", "UK", "China", "Japan", "Germany", "Australia" }; var data = countryArr.Where(a => a.Length < 5).Select(a => a); foreach (string sdata in data)             { Console.WriteLine(sdata);
O/P : - USA, UK

Above code can be written using Anonymous function

Write below function

Func<string, bool> wh = delegate (string s)         { return s.Length < 5; }; Func<string, string> sel = delegate (string s)         { return s; };
Below function to implement the LINQ

privatevoid PrintData()         { string[] countryArr = { "India", "USA", "UK", "China", "Ja…