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 a 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#

In this blog, we will see Active Directory Programming using C# code.
In other blogs, you can read ASP.Net Tutorial, .Net Core Tutorial.
We will first understand - What is Active Directory?

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

In this blog, we will see HTML form validation code in JavaScript. My another blog on AMP HTML and Angular JS.

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

Below are few important SharePoint interview questions and their answers.

Important C# Interview Questions and Answers

In this blog, I have collected questions and answers of c# asked in the interview.

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

Important ASP.Net Interview Questions and Answers

In this blog, I have collected important 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 the different platform.
See more about web service at this URL:

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.

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 in SharePoint? Why to use it?

Delegate control in SharePoint allows developers to manage control on a 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 an associated feature is de-active delegate control will not be visible to users.

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.

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…

How to overload a web method in web service - ASP.Net

We can define Method Overloading as , Same Methods name with different type of parameter or different set of parameters.

Web method overloading is not straight forward in use.

C# Code to get user details from FaceBook

In this blog i am going to explain about how some one can get user details from Facebook and later use data for user registration, user login and for some other purpose.

First you need to create a Facebook APP, You can check here how to create facebook app.

How to create a blank SharePoint Page? SharePoint Branding

I was working on a project where all my SharePoint inherits from a custom master page with predefined Page Layout.

I got a requirement where i need to create few pages with different layouts.

There are various ways to do this. One is to create a new Page Layout by coding and select your layout while adding new page to Page library, another way is to create a new master page (i.e. create a blank master page).

I followed second option. I created a copy of existing master and modified it accordingly.

I added a page with existing Page Layout.I opened that page in SharePoint Designer 2010 and changed the master page name from top of the section.

<%@ Page language="C#" MasterPageFile="../_catalogs/masterpage/blank.master" ......

I checked in file and published.but it was showing my custom master page layout.This is because your page is attached with an existing Page Layout.To detach page layout, open Page Library, Right Click on Page and Select "Detach from Page La…

Introduction to Linq to SharePoint

Introduction to Linq to SharePoint
LINQ is a way to access external data sources.SharePoint Foundation 2010 comes with its own LINQ to SharePoint provider.
The namespace which contains the provider is Microsoft.SharePoint.Linq.dll.

What is Parent Content Type in SharePoint 2010?

What is Parent Content Type in SharePoint 2010?As you know content type in SharePoint gives re-usability features.
Parent Content Type is a hierarchical relationship between two content types. Parent Content Type defines the properties for a child content type which inherits all properties of parent content type.

How to create workflow in SharePoint Designer

Workflow is a process to break down a job/work into several segments to make the business easy and simple. Or, Workflows in SharePoint Designer are there to help you to create automated business processes. A sample workflow is a simple approval workflow. When an item is saved to a SharePoint list with an approval workflow association, the item is routed to an "approver", where he can then either approve or reject the new item.

For example, suppose some people in your organization have the task to write, review, and approve contracts. They save them in a document library in their team website. To help them automate administration, you can use SharePoint Designer to create a route that sends an e - mail message to the reviewer when a new agreement has been added to the site. At the same time, a task can be created in the reviewer ’ s task list. When the person reviewing this agreement specifi es that the task is complete (approved or not), a variety of actions can be set thro…

Facebook login on website with Java Script Code

Facebook is a popular social media. Most of the website provide login with facebook feature, why because each and every user over internet have facebook account. So login with facebook feature avoid filling a new signup form on a new website.

How to Crop and Upload image using JQuery

In this blog, I will explain how to crop an image and then upload that image using JQuery. Here you will come to know about preview an image, and then crop that image and finally upload it using JQuery and C# code.  This implementation has been done using JQuery, so no postback only smooth user experience.