Thursday, December 4, 2014

C# When to use if else and when to use ternary operator

If you have any control flow, then use if else

int a = 1;
int b = 3;

// Use negated expression.
if (!(a == 1 && b == 2))
//Do some thing..

// Use binary or version.
if (a != 1 || b != 2)
{//Do some thing..

If you have any condition, based on condition if you want to assign any value then use ternary operator

int input = Convert.ToInt32(Console.ReadLine());
string classify;
classify = (input < 0) ? "negative" : "positive";

Advantages of using ADO.NET

• All data in ADO.NET is transported in XML format
• ADO.NET can improve overall development time
• ADO.NET supports a variety of development needs
• ADO.NET can be used from all programming languages that target the .NET Framework

Tuesday, December 2, 2014

Error in Web parts after SharePoint platform upgrade

Using MOSS 2007 web part code, i have re build the VS 2010 SharePoint project. After deploying the webpart, i was getting error.

I have added below tag in web.config

SafeControl Assembly="MyCustomWebpart, Version=, Culture=neutral, PublicKeyToken=bdb4a6220fe9433c” Namespace="MyProject.UI.WebParts” TypeName="ListItemReport" Safe="True" SafeAgainstScript="True"

SharePoint remove and repair the broken Web Part

Some times, you will see some webparts shows error, but will not able to delete that web parts.
Using below url, you will able to delete the webparts.


You will see all error-ed webparts, select webpart and delete.

Error occurred in deployment step 'Activate Features': Cannot start service SPUserCodeV4 on computer

Root Cause: Microsoft SharePoint Foundation Sandboxed Code Service is stopped.
Open Central Administration site
go to System Settings
lick on Manage Service on server
Check to see if Microsoft SharePoint Foundation Sandboxed Code Service  is running, it should be stopped
Start the service and try deploying the Sandboxed solution

Monday, December 1, 2014

Migrate MOSS 2007 Custom webpart to SharePoint 2010

First Get MOSS 2007 code.

Open VS 2010
Create new Empty SharePoint Project.
Add New webpart.
Now delete .cs from solution.
Right click on Web part folder Add existing item.
Select .cs file from old MOSS 2007 code folder.
Resolve all references and errors.

Unable to display this web part. To troubleshoot the problem, open this web page in a Microsoft SharePoint Foundation-Compatible HTML editor such as Microsoft SharePoint Designer

Error: Unable to display this web part. To troubleshoot the problem, open this web page in a Microsoft SharePoint Foundation-Compatible HTML editor such as Microsoft SharePoint Designer. If the problem persists, contact your Web Server Administrator. Correlation ID.
This error occurs when the “AllowPersonalization” property of the Web Part Zone is set to false, and a user with less privilege tries to access the zone. This leads to the WebPartPageUsageException. This could be overcome by just setting the AllowPersonalization property to true.

Error parameter name ncolindex

parameter name ncolindex
This is a bug with SQL management studio and I need to use TSQL to attach the database
USE [master]
CREATE DATABASE [WSS_Content_Databasename] ON
( FILENAME = N’E:\MSSQL\MSSQLSERVER.DB\Data01\WSS_Content_databasename.mdf’ ),
( FILENAME = N’E:\MSSQL\MSSQLSERVER.DB\Data01\WSS_Content_databasename_log.LDF’ )
if exists (select name from master.sys.databases sd where name = N’WSS_Content_databasename’ and SUSER_SNAME(sd.owner_sid) = SUSER_SNAME() ) EXEC [WSS_Content_databasename].dbo.sp_changedbowner @loginame=N’sa’, @map=false


1) Return Multiple Resultsets

2) Connection Pooling and Object Pooling

3) Use SqlDataReader Instead of Dataset wherever it is possible

4) Keep Your Datasets Lean

5) Avoid Inefficient queries

6) Unnecessary round trips

7) Too many open connections

8) Avoid Transaction misuse

9) Avoid Over Normalized tables

10) Reduce Serialization

11) Do Not Use CommandBuilder at Run Time

12) Use Stored Procedures Whenever Possible

13) Avoid Auto-Generated Commands

14) Use Sequential Access as Often as Possible

How to set, Person or Group field to Empty or Null in SharePoint using JSOM

Today i was trying to set null value to Person or Group field.
It was not straight way..


var objUser = new Array();
Assign empty array to column of type "Person or Group"
ojLstItem.set_item('MyPersonColumnName', objUser)