Posts

Showing posts from July, 2013

Steps to use LINQ in SharePoint

In order to use LINQ in SharePoint, firstly we need to create a Data Context class. The steps to be followed are as follows: Open up the SharePoint Management Shell and give the command SPMETAL /web:<url of the web site> /code:<the name of the class file> Once the file has been generated add the same to the project where it needs to be used We need to add a reference to the class "Microsoft.SharePoint.Linq" In the Visual Web Part class where we need to use the LINQ we need to add a reference to the "Microsoft.SharePoint.Linq" and "System.Linq" We need to then create an object of the Data Context class created and use the same for CRUD operations

What is the difference between ExecuteNonQuery, ExecuteScalar and ExecuteReader?

All these methods are used to manipulate or retrieve data from the database. The details are as folllows: ExecuteNonQuery The method executes a transaction (Insert/Update/Delete) and returns the number of rows affected, in addition if there are triggers associated with the table the number of rows affected by that will also be returned. ExecuteSclar The methods only returns the value from the first cell of the first row, this is used for commands like COUNT etc which returns a single value. ExecuteReader This method is used to read data from the table and return the same, the return value creates a SQLDataReader object.

Explain normalization in SQL Server

Normalization is the process of organizing data into a related table; it also eliminates redundancy and increases the integrity which improves performance of the query. Database normalization can essentially be defined as the practice of optimizing table structures. Optimization is accomplished as a result of a thorough investigation of the various pieces of data that will be stored within the database, in particular concentrating upon how this data is interrelated. Normalization avoids: Avoids Duplicates - it makes sure that duplicate data is not stored Insert Anomaly - A record about an entity cannot be inserted into the table without first inserting information about another entity - Cannot enter a customer without a sales order Update Anomaly - Cannot update information without changing information in many places. To update customer information, it must be updated for each sales order the customer has placed Delete Anomaly - A record cannot be deleted without d...

Explaing locking in SQL Server

In SQL Server locking can be done at various levels, the levels are as follows: RID - this is used to lock a single row Key - this is used to lock rows within an index Page - this is used to lock a 8 KB data page or index page Extent - this is used to lock contiguous 8 data pages or index pages Table - this is used to lock a table including the data and index Database - this is used to lock the full database The various types of locking that are available are as follows: Shared Lock (S) Shared lock is used for concurrent read operations (SELECT), once the read operation is done the lock is released unless the lock has been specified as a repeated process or a locking hint has been used to keep the lock till the duration of the transaction. Update Lock (U) This type of lock is used on resources that can be updated and prevents the common type of deadlock where by two transactions are trying to update at the same time. Only one transaction can obtain an Update lock, if any ...

What is the difference between DDL, DML and DCL?

Data Definition Language (DDL) There are called data definition cause they define the data Create - creates objects in the database Alter - alters objects in the database Drop - deletes objects in the database Truncate - deletes all records from the table along with the space Rename - renames objects in the database Data Manipulation Language (DML) These are used for data manipulation Select - selects records from the table Insert - create a new record in the table Update - updates the records in the table Delete - deletes all the records in the table, but the space remains Lock Table - locks a table for controlling data concurrency Data Control Language (DCL) This is used to control the data, that the data that can be accessed by the user based on his privilege Grant - grants users access to the database Revoke - removes the access of the user to the database Transaction Control Language (TCL) This is used to control the changes done by the DML statemets C...

What is a Static method?

Static methods are those which can be called from another class without instantiating an object of the class where it has been declared. It can be called directly after the class name for e.g. classname.staticmethod A static method is declared by using the keyword 'static'

What is Polymorphism?

By Polymorphism we mean one state having different forms, polymorphism is implemented by the use of method overloading or overriding. Polymorphism is of two types which are as follows: Compile Type Polymorphism or Early Binding or Static Binding This is the process whereby the compiler already identifies which method to execute at the compilation time itself. The main advantage is that the execution is much faster and the disadvantage is that it is not flexible. Examples: Method Overloading or Overriding Run Time Polymorphism or Late Binding or Dynamic Binding This is the process whereby he compiler identifies which method to execute at runtime. The main advantage is that it is flexible and the disadvantage is that the execution speed is much slow. Examples: Overridden Methods which are using the base class object

What is Inheritance?

Inheritance is a relationship between classes where one class is the parent/super class of another. Classes can inherit from another class only, it cannot inherit from multiple classes but can inherit from multiple Interfaces. This is accomplished by putting a colon after the class name when declaring the class and naming the class to inherit from—the base class—after the colon. The different types of inheritance that are there are as follows: Single Inheritance In this type one child class is created from one base class Hierarchical Inheritance In this type more than one child class is created from a single base class Multi-Level Inheritance In this type one child class is derived from a class which is derived from another base class Hybrid Inheritance This type is a combination of Single, Multi-level and Hierarchical inheritance Multiple Inheritance This type is not supported by C# where a class is derived from multiple base classes, but a class can be derived from one bas...

What is an Abstract Class?

An abstract class is a special class which cannot be instantiated but it needs to be implemented in the sub class. The methods declared within the class needs to be implemented (in the abstract class we only have the declaration for the method) in the sub class using the " override " keyword. The abstract class or method declared needs to have the keyword " abstract ". An abstract class can inherit from a class and one or more interfaces An abstract class can implement code with non-Abstract methods An Abstract class can have modifiers for methods, properties etc An Abstract class can have constants and fields An abstract class can implement a property An abstract class can have constructors or destructors An abstract class cannot be inherited from by structures An abstract class cannot support multiple inheritance  Reference: http://www.c-sharpcorner.com/uploadfile/annathurai/abstract-class-in-C-Sharp/ http://www.codepr...

What is Method Hiding?

If methods are declared in a child and base class with the same signature but without the keywords virtual and override , the child class function is said to hide the base class function. The method in the child class is denoted with the New keyword. For e.g. public class VirtualDemo {     public void Hello ()     {         Console.WriteLine("Hello in Base Class");     } } public class A : VirtualDemo {    public new void Hello ()    {       Console.WriteLine("Hello in Derived Class");    } }

What is Method Overriding?

Method Overriding is a process by which the abstract methods that are declared in the abstract class are implemented in the child class, that is the class where the abstract class is inherited. The method should be preceded by the keyword " override " or " virtual " and should be having the same signature, that is the same return type, same number of parameters and type. The virtual methods does have an implementation which can be overridden in the sub class where as an abstract method must be implemented in the sub class. For e.g. public class A {      public virtual double Area (double r)      {           return r * r;      } } public class B : A {      public override double Area (double r)     {         double p = 3.142;         return base.Area(r) * p;     }...

What is Method Overloading?

Method overloading is a process whereby methods by the same name are declared more than once but with a different signature, it can either be the number of parameters or the type of the parameters. This is provided to overcome the optional parameter options that is there in VB.NET. For e.g. public void methodOverloading (int arg1, int agr2) public void methodOverloading (int arg1, string arg2) public void methodOverloading (int arg1, int agr2, string arg3)

What is the difference between Site Definition and Site Template?

Site Definition Site Definition can be said to be the foundation for building a site in SharePoint, it contains all the artifacts that are needed for the site. A Site Definition can contain multiple site definition configuration. It is a collection of XML (using CAML) and ASPX pages. Each site definition consists of a combination of files that are placed in the %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE\SiteTemplates sub folders of SharePoint Foundation servers during installation of SharePoint Foundation. The XML markup in the site definition files may include references to files in other sub folders of %ProgramFiles%\Common Files\Microsoft Shared\web server extensions\14\TEMPLATE , including .xml, .aspx, .ascx and .master page files, in addition to document template files (.dot, .html) and content files (.gif, .doc). The files related to the Site Definition are stored in the file system of the server and not in the content database. ...

What is the difference between .dwp and .webaprt file in SharePoint?

As such there is no difference between the files based on the usage, they are the same only the version of SharePoint for which it is being used is different. .dwp file is used for version 2 while .webpart is used for version 3. The version of the SharePoint is specified in the xmlns tag In the .webpart file all the properties are provided in separate property tags with a name attribute where as in .dwp file there is a different tag for all the properties.

Steps to create Custom Columns and Custom Content Type using Visual Studio

The steps to be followed to create a custom content type using visual studio are as follows: Open up the VS 2010 with the Admin priviledge Create a new " Content Type Project " Provide the URL of the site where the content type needs to be created and validate it If required deploy it as a SandBox Solution or else deploy it as a Farm Solution and click on the Finish button, this will create the solution Choose the base content type, for e.g. " Item " and click on the Finish button Set the scope of the feature as " Site " or whatever is needed In the Solution Explorer under the name provided for the content type there will be a file as " Elements.xml ", open up the file, it is good to rename the xml file e.g. XXXContentType.xml In this file we need to provide the following details: ID - this is the GUID which is autogenerated Name - the name of the content type Description - the description of the content type Group - the headin...

What is the difference between a Page Layout and Master Page in SharePoint?

A Page Layout is nothing but a template which when used in conjuncture with the Master Page gives the look and feel and contents of the page. Each page layout has an associated content type that determines the kind of content that can be stored on pages based on that page layout. Master Pages and Page Layouts dictate the overall look and feel of your SharePoint site. Master Pages contain controls that are shared across multiple page layouts, such as navigation, search, or language-preference for multilingual sites. Page layouts contain field controls and Web Parts. All page layouts reference a master page that is based on the CustomMasterUrl property of the SPWeb class. The top-level SharePoint Server site for a site collection hosted on SharePoint Server 2010 has a special document library called the Master Page and Page Layout Gallery. All Page Layouts and Master Pages are stored in this document library. Reference: http://blog.beckybertram.com/Lists/Posts/Post...

What is the difference between the SPListItem.Update() and SPListItem.SystemUpdate() methods?

The SPListItem.Update() method is the general use by which the data is a updated to the list along with the changes to the fields Modified, ModifiedBy and to the Version, if it is enabled. But by using the method SPListItem.SystemUpdate(), the changes are reflected to the list but there is no change in the Modified, ModifiedBy field and the Version is also not updated if enabled.