Monday, 12 March 2018

SharePoint Event Receivers

Event Receiver is an important feature of SharePoint. The use of Event Receiver is to handle the events. It is like a method that is triggered when an action occurs on a specified SharePoint object. Triggering actions have some activities including,
  1. Adding
  2. Updating
  3. Deleting
  4. Moving
  5. Checking In
  6. Checking Out.
We may need to perform some actions like notifying the person who created the list item, or deleted it. By using Event Receivers, we can easily maintain the secured data in SharePoint.

Example

There is a Document Library and the full permission has been given to your Manager. So, we need to configure that document library in a manner that if anyone is trying to add a document in a library, your manager will get an alert like "someone is trying to add documents in library. We need you approval. " Once your Manager approves, then only the user can add a document in library.

Once a user has added a document in a library, an auto-generated message will be sent to your manager. At this time, we require Event Receiver to do this thing.

Types of Event Receiver
There are two types of Event Receiver in SharePoint,
  1. Synchronous Event Receiver
  2. Asynchronous Event Receiver
Synchronous Event Receiver or Before Event Receiver
Before events fire before the corresponding event action occurs and before SharePoint has written any data to the content database.

Asynchronous Event Receiver or After Event Receiver
After events fire after the event action has completed and after SharePoint has written to the content database to commit the event action. After events do not support cancelling the event action. A common example is sending out email notifications to let all the members of a site know when a new document has been uploaded.

Classes of SharePoint Event Receiver
  • Base class: Microsoft.SharePoint.SPEventReceiverBase.
  • Base class for List Item: Microsoft.SharePoint.SPItemEventReceiver
  • Base class for SharePoint List: Microsoft.SharePoint.SPListEventReceiver
  • Base class for Email: Microsoft.SharePoint.SPEmailEventReceiver
We can use the event to perform the following activities
  • Validate the Item
  • Log the information
  • Create associated items
Event Receiver Base Classes
  • SPItemEventReceiver
  • SPListEventReceiver
  • SPEmailEventReceiver
  • SPWebEventReceiver
  • SPWorkflowEventReceiver

Sunday, 28 January 2018

OOPS Concepts


Class

 It is a collection of objects.

Object

Objects are the basic run-time entities of an object-oriented system. They may represent a person, a place or any item that the program must handle. 
Encapsulation
·         Wrapping up a data member and a method together into a single unit (in other words class) is called Encapsulation.
·         Encapsulation is like enclosing in a capsule. That is enclosing the related operations and data related to an object into that object.
·         Encapsulation is like your bag in which you can keep your pen, book etcetera. It means this is the property of encapsulating members and functions.
·         Encapsulation is a technique used to protect the information in an object from another object.
Abstraction
·         Abstraction is "To represent the essential feature without representing the background details."
·         Abstraction is a process of hiding the implementation details and displaying the essential features.
·         Abstraction is a mechanism to provide the essential features without describing the background details. Means provide the functions to access the hidden (private) data.
·         The importance of abstraction is derived from its ability to hide irrelevant details and from the use of names to reference objects. Abstraction is essential in the construction of programs. It places the emphasis on what an object is or does rather than how it is represented or how it works. Thus, it is the primary means of managing complexity in large programs.

The Differences between Abstraction and Encapsulation

Abstraction
Encapsulation
1. Abstraction solves the problem at the design level.
1. Encapsulation solves the problem at the implementation level.
2. Abstraction hides unwanted data and provides relevant data.
2. Encapsulation means hiding the code and data into a single unit to protect the data from the outside world.
3. Abstraction lets you focus on what the object does instead of how it does it
3. Encapsulation means hiding the internal details or mechanics of how an object does something.
4. Abstraction: Outer layout, used in terms of design.
For example:
An external of a Mobile Phone, like it has a display screen and keypad buttons to dial a number.
4. Encapsulation- Inner layout, used in terms of implementation.
For example the internal details of a Mobile Phone, how the keypad button and display screen are connected to each other using circuits.


Polymorphism
Polymorphism means one thing in many forms. Basically, polymorphism is a capability of one object to behave in multiple ways. Example: A man role changes at home, college, and outside the home. There are following types of polymorphism:
1.       Static polymorphism (compile time): It is achieved using function overloading and operator overloading.
2.       Dynamic polymorphism (runtime time)It is achieved using function overriding means using the virtual function.
Polymorphism provides following features: 
  • It allows you to invoke methods of the derived class through base class reference during runtime.
  • It has the ability for classes to provide different implementations of methods that are called by the same name.

Polymorphism is of two types: 
  • Compile time polymorphism/Overloading
  • Runtime polymorphism/Overriding

Compile Time Polymorphism 
Compile time polymorphism is a method and operators overloading. It is also called early binding. 
In method overloading method performs the different task at the different input parameters. 

Runtime Time Polymorphism 
Runtime time polymorphism is done using inheritance and virtual functions. Method overriding is called runtime polymorphism. It is also called late binding. 
When overriding a method, you change the behavior of the method for the derived class. Overloading a method simply involves having another method with the same prototype.

Sealed Class

What is the use of sealed classes in c#? Generally, if we create classes we can inherit the properties of that created class in any class without having any restrictions. In some situation, we will get requirement like we don’t want to give permission for the users to derive the classes from it or don’t allow users to inherit the properties from the particular class in that situations what we can do? 
For that purpose, we have a keyword called “Sealed” in OOPS. When we defined class with keyword “Sealed” then we don’t have a chance to derive that particular class and we don’t have permission to inherit the properties from that particular class.

Method Hiding( new keyword)

Method hiding in C# is similar to the function overriding feature in C++. Functions of the base class are available to the derived class. If the derived class is not happy, one of the functions available to it from the base class can define its own version of the same function with the same function signature, just differing in implementation. This new definition hides the base class definition.

Virtual and Overridden Methods

Only if a method is declared virtual, derived classes can override this method if they are explicitly declared to override the virtual base class method with the override keyword.
    using System;
    namespace Polymorphism
    {
        class A
        {
            public virtual void Foo() { Console.WriteLine("A::Foo()"); }
        }

        class B : A
        {
            public override void Foo() { Console.WriteLine("B::Foo()"); }
        }

        class Test
        {
            static void Main(string[] args)
            {
                A a;
                B b;

                a = new A();
                b = new B();
                a.Foo();  // output --> "A::Foo()"
                b.Foo();  // output --> "B::Foo()"

                a = new B();
                a.Foo();  // output --> "B::Foo()"
            }
        }

Constructors and Destructors

Constructors

A constructor is a special function that is a member of the Class and has the same name as that of the Class. Every Object created would have a copy of member data which requires initialization before it can be used. This initialization is common in Object-Oriented Language, which allows the object to initialize themselves as and when they created. This automatic initialization is performing through the use of constructor functions. The constructor methods exist to simplify the process of initializing class member variables within a class.

Declaration of Constructors 

public class Car
{
        int start;
        public Car()
        {
               //Add constructor task here
               start = 0;
        }
}
A constructor is optional if no constructors are declared for a class, the compiler invokes a default constructor for you. The default constructor simply sets all the fields in the class to their default values. You can define as many constructors as you want, as long as each constructor has a different parameter list. Also not that constructor functions cannot return values.

Destructors

A destructor is a function that has the same name as that of the class but is prefixed with a ~(tilde). Destructors de-initialize Object when they are destroyed. You can think of destructors as the opposite of constructors: constructors execute when objects are created, and destructors execute when the objects are destroyed by the built-in Garbage Collection facility. This process occurs behind the scenes with no consequence to the programmer.

Declaration of Destructors 

public class Car
{
        int start;
        //constructor
        public Car()
        {
               start = 0;
        }
        //destructor
        ~Car()
        {
               start = 0;
        }
}
Destructors are optional. Destructors cannot return any values; nor can they accept any parameters. Unlike constructors, you cannot have more than one destructor defined for a class.



Tuesday, 25 February 2014

SharePoint Site Architecture

The following diagram shows the SharePoint Foundation site architecture in relation to the collections and objects of the Microsoft.SharePoint namespace.
Site Achitecture
  1. Each SPSiteobject, despite its singular name, represents a set of logically related SPWeb objects (see below). Such a set is commonly called a "site collection," but SPSite is not a standard Microsoft .NET collection class, in contrast to SPWebCollection. Rather, it has members that can be used to manage the site collection. The AllWebs property provides access to theSPWebCollection object that represents the collection of all Web sites within the site collection, including the top-level site. The SPSite.OpenWebmethod of the SPSite class returns a specific Web site.
  2. Each site collection includes any number of SPWeb objects, and each object has members that can be used to manage a site, including its template and theme, as well as to access files and folders on the site. The Webs property returns an SPWebCollection object that represents all the subsites of a specified site, and the Lists property returns an SPListCollection object that represents all the lists in the site.
  3. Each SPList object has members that are used to manage the list or access items in the list. The GetItems method can be used to perform queries that return specific items. The Fields property returns an SPFieldCollection object that represents all the fields, or columns, in the list, and the Items property returns an SPListItemCollection object that represents all the items, or rows, in the list.
  4. Each SPField object has members that contain settings for the field.
  5. Each SPListItem object represents a single row in the list.

SharePoint Server Architecture

The following diagram shows the SharePoint Foundation server architecture in relation to the collections and objects of the Microsoft.SharePoint.Administration namespace.
Server architecture and Administration namespace
  1. The SPFarm object is the highest object within the SharePoint Foundation object model hierarchy. The Servers property gets a collection representing all the servers in the deployment, and theServices property gets a collection representing all the services.
  2. Each SPServer object represents a physical server computer. The ServiceInstances property provides access to the set of individual service instances that run on the individual computer.
  3. Each SPService object represents a logical service installed in the server farm. Derived types of the SPService class include, for example, objects for Windows services, such as the timer service, search, the database service, etc. and also objects for Web services, such as the basic content publishing Web service which supports the Web applications.
  4. An SPWebService object provides access to configuration settings for a specific logical service or application. The WebApplications property gets the collection of Web applications that run the service.
  5. If the service implements the Service Application Framework of SharePoint Foundation, then it can be split into multiple configured farm-scoped instantiations (CFSIs). Each of these provides the functionality of the service but each has its own individual permission and provisioning settings.
  6. Each instance of a service, or a CFSI, that is running on a specific server is represented by an SPServiceInstance object.
  7. An SPDatabaseServiceInstance object represents a single instance of a database service running on the database server computer. The SPDatabaseServiceInstance class derives from theSPServiceInstance class and thus inherits the Service property, which provides access to the service or application that the instance implements. The Databases property gets the collection of content databases used in the service.
  8. Each SPWebApplication object represents a Web application hosted in an Internet Information Services (IIS) Web site. The SPWebApplication object provides access to credentials and other farm-wide application settings. The Sites property gets the collection of site collections within the Web application, and the ContentDatabases property gets the collection of content databases used in the Web application.
  9. An SPContentDatabase object inherits from the SPDatabase class and represents a database that contains user data for a Web application. The Sites property gets the collection of site collections for which the content database stores data, and the WebApplication property gets the parent Web application.
  10. An SPSiteCollection object represents the collection of site collections within the Web application.

Sunday, 9 September 2012

What is Sandbox Solutions in SharePoint 2010?

Sandbox solution is a new feature introduced in SharePoint 2010. It's a secured wrapper around webparts and other elements with limitations. There is no thumb rule that every webpart in SharePoint 2010 belongs to Sandbox Solution. But it's recommended to develop webparts with Sandbox solution. It allows administrators to monitor the solutions and control as required. SharePoint Site Collection administrators can view the resource utilization of each solution and can block if it consumes too much resources. Usually when sites working slow, developers complain the server is slow whereas site/server administrators blame on Develepor code/solutions. Now Microsoft put a Full Stop to that. :)

Technically speaking SharePoint solutions run in seperate worker processes and not in w3wp.exe. So It doesn't require IIS Reset or Application Pool Recycling. Without disturbing the SharePoint site, Sandbox solutions can be deployed. Only thing while deploying new version of Sandbox solution over existing solution, SharePoint will display No Solution found error in Sandbox Webparts on the page. However within seconds sandbox solutions getting deployed and it'll start working. In SharePoint 2007, only farm administrators can install/deploy developer solutions. But Now site collection administrators can deploy solutions with web based interface. This reduces the dependency of Farm Administrator and improves rapid deployment.

Sandbox Processes
Here the processes which required for Sandbox solutions.
  1. SPUCWorkerprocess.exe - Sandbox Worker process service which is a Seperate Service Application which actually executes Sandbox code. It should be started in every farm to use Sandbox solutions.
  2. SPUCWorkerProcessProxy.exe - Sandbox Worker process proxy which is working as a proxy for Worker process and takes care of Sandbox code execution. It can also serve to other farms if configured. Basically it helps site administrator for load balancing.
  3. SPUCHostService.exe - Sandbox User Code Service takes care of user code in Sandbox amd it can be started in the farms where to use Sandbox solutions.
Sandbox Limitations
As I said before, Sandbox is a secured wrapper and it has restrictions on code to run in SharePoint environment. Few Key limitations which developers should know are listed below.
  1. No Security Elevation - RunWithElevatedPrivileges which runs the specified block of code in application pool account(typically System Account) context is not allowed in Sandbox code. SPSecurity class also not allowed to use in Sandbox.
  2. No Email Support - SPUtility.SendMail method has been blocked explicitly in Sandbox, However .Net mail classes can be used to send mails. Additionaly sandbox won't allow to read Farm SMTP address. So developers has to specify the SMTP address in code itself(may be some other workaround).
  3. No Support to WebPartPages Namespace - Sandbox won't allow to use Microsoft.SharePoint.WebPartPages namespace.
  4. No Support to external Webservice - Internet web service calls are not allowed to ensure security in Sandbox solutions. Allow Partially Trusted code also can't be accessed within Sandbox.
  5. No GAC Deployment - Sandbox solutions are not stored in File System(Physical path) and assemblies can't be deployed to Global Assembly Cache(GAC). But it's available on C:\ProgramData\Microsoft\SharePoint\UCCache at runtime. Note the ProgramData is a hidden folder.
  6. No Visual Webparts - Visual Studio 2010 by default won't allow to create Visual Webparts to deploy as sandbox solution. But with Visual Studio PowerTools extensions(downloadable from Microsoft MSDN website) Visual Webparts can be developed and deployed as sandbox Solutions.
SharePoint Online which is SharePoint environment provided by Microsoft to manage SharePoint Sites in internet accepts only Sandbox solutions. Because SharePoint Online sites are Windows Servers at Microsoft Datacenters, Microsoft won't allow GAC deployment or file system access. In future Sandbox solution will give more features for developers.

AD property details


Name
LDAP Provider Property Name
Syntax
First Name
givenName
String
Initials
initials
String
Last name
sn
String
Display name
displayName
String
Description
description
String
Office
physicalDeliveryOfficeName
String
Telephone number
telephoneNumber
String
Other Telephone numbers
otherTelephone
String
E-mail
mail
String
Web page
wWWHomePage
String
Other Web pages
url
String
Street
streetAddress
String
P.O. Box
postOfficeBox
String
City
l
String
State/province
st
String
Zip/Postal Code
postalCode
String
Country/region
c, co, countryCode
String
User logon name
userPrincipalName
String
pre-Windows 2000 logon name
sAMAccountName
String
Account disabled?
userAccountControl
Boolean
User Profile path
profilePath
String
Logon script
scriptPath
String
Home folder, local path
homeDirectory
String
Home folder, Connect, Drive
homeDrive
String
Home folder, Connect, To:
homeDirectory
String
Title
title
String
Department
department
String
Company
company
String
Manager
manager
String
Mobile
mobile
String
Fax
facsimileTelephoneNumber
String
Notes
info
String