Monday, September 27, 2010

Important Considerations for SharePoint Master Pages

Consider the following when you are working with master pages in Windows SharePoint Services:

1. Compilation mode for master pages works like the compilation mode for any other .aspx page. You can change the compilation mode at any time, and you can combine compilation modes for master and content pages, for example, a compiled master page and a content page that is not compiled. Remember, however, that although compiled master pages can contain inline script, after that page is customized in Office SharePoint Designer, or a similar tool, the page is no longer compiled and script no longer runs. For that reason, it is recommended that you do not include inline script in your master pages.

2. By default, Windows SharePoint Services does not use nested master pages, but does not block users from using them. You can create master pages at any level, and have a master page that refers to another master page. For example, you can reference one master page from another master page using the following directive:

<%@ Master master=MyParent.master %>

Some page editors may not effectively support nested master pages.

3. You cannot add Web Parts in zones to a master page. You can add static Web Parts (parts outside of a zone) to a master page, but you cannot add dynamic Web Parts to master pages. You can add zones to master pages and later add Web Parts to the zone in the browser, but the Web Parts are associated with the content page.

Sunday, August 1, 2010

Few notes about Abstract class and Interfaces...

when you believe that derive class behavior & action would be similar to base in most of the case you use abstract; and when you think that behavior is same but action can change for different derived classes you use interface.

Abstract base class shows is-a relationship while interface shows "can do" relationship for ex: humans and fish can swim while human and horse can run and human, horse and fish are (is a) animals.

So abstract class Animal can be a base class inherited by all humans, horse and fish. While animal itself doesn't represent any physical entity so abstract. A behavior "breath" will be applied to all in animals if defined in animal abstract class itself. May be later on you may want to add "Eat" behavior in abstract class which would not create any consequences on derived class. Or you might support another version of animal which can represent the abstract properties of aliens too.

while Interface IRun will be inherited by human and horse only while ISwim can be inherited by human and Fish only and all these derived classes will define their own style of swimming and running while if you add another behavior in same interface you have to define it in all the derived class.

Sample implementation will be like

Class Human: Animals, IRun, ISwim{}

Class Horse: Animals, IRun{}

Class Fish: Animals,ISwim{}

Class Bird: Animals, IFly{}

later on updated versions of animal

Class Alien: Animals, IFly, ISwim, IRun, ISpace {} //though hypothetical considered just for example :)
REF: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/0ab0d038-61b6-43e0-82da-33338f52f3bf

Why abstract allows constructor? What is the use of it?

So that derived class can call it where creating it's object and abstract base class can initialize it's members.

"Because abstract classes should never be instantiated, it is important to correctly define their constructors. It is also important to ensure that the functionality of your abstract class is correct and easily extended. The following guidelines help ensure that your abstract classes are correctly designed and work as expected when implemented.

Do not define public or protected internal (Protected Friend in Visual Basic) constructors in abstract types &define a protected or an internal constructor in abstract classes:

Constructors with public or protected internal visibility are for types that can be instantiated. Abstract types can never be instantiated. If you define a protected constructor in an abstract class, the base class can perform initialization tasks when instances of a derived class are created. An internal constructor prevents the abstract class from being used as the base class of types that are not in the same assembly as the abstract class. "

http://msdn.microsoft.com/en-us/library/ms229047.aspx

REF: http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/175aad18-4514-4320-8195-be480dee4627

Why use reference of abstract class to create object

It is more related to OOPS concept rather than how we do it C#. Liskov substitution principle explain the relation in the best way

"Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T". Here you can assume T as TextWriter and S as Stream Writer

http://en.wikipedia.org/wiki/Subtype#Subtyping_schemes

In Particular to .net concept TextWriter is more generic offer basic functionality to write Streams (StreamWriter) and strings (StringWriter) to a file

REF: http://social.msdn.microsoft.com/Forums/en-US/netfxbcl/thread/aa53228f-6d2d-4475-8d7c-8081057f22f9

Friday, July 30, 2010

Why Feature stapling in SharePoint

sometimes you may want to attach your feature with site definition i.e. whenever someone create a site using particular site definition you might want to activate the feature by default, and in same scenario it may be possible that you do not own the site definition hence cannot modify the existing site definition to attach feature (like SharePoint default site def e.g. team site\publishing\collaboration).

In these cases you can write a feature and can attach the feature itself with the site definition.

From MSDN :
"Causes the attachment of a Feature to all new instances of sites that use a given site definition, without modifying the site definition or creating code routines to activate the Feature on each site. Also known as a feature site template association"

Following is an example of feature stapling that associates the Feature with only the STS site definition template

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<FeatureSiteTemplateAssociation Id="00BFE171-1B17-4F72-28CB-1171C0140130" TemplateName="STS#0" />
</Elements>

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/5e27a15b-5ceb-4706-b660-aadad03e0f3c