Share Point Interview
Share Point Interview
Share Point Interview
The Microsoft.Office.Server namespace is the root namespace of all Office Server objects
and Microsoft.SharePoint is the root namespace for all WSS objects.
Read More at SharePoint 2007 Object Model
c
!
To debug SharePoint webpart (or any solution) you can simply drag and drop your
complied .dll in GAC and recycle the app pool. You can also run upgrade solution command
from stsadm.
To retrieve large number of items with a better performance we can either use
SPQuery or PortalSiteMapProvider Class (PortalSiteMapProvider is only available in MOSS).
Read More with Examples
Retrieving large number of Items from sharepoint list
c
!' !
You do not deploy a code behind file with your custom Layouts page. Instead, you can
have the page inherit from the complied dll of the solution to access the code behind.
Ans. Site Definitions are stored on the hard drive of the SharePoint front end servers. They
are used by the SharePoint application to generate the sites users can create. Site
Templates are created by users as a copy of a site they have configured and modified so
that they do not have to recreate lists, libraries, views and columns every time they need a
new instance of a site.
You can deploy the css or javascript files in _layouts folder in SharePoint's 12 hive. To
use them in your webpart, you need to first register them to your webpart page and then
specify a virtual path for the file for e.g. _layouts\MyCSS.css See Code examples at Using
External Javascript, CSS or Image File in a WebPart.
According to the best Practices you should always dispose them if you have created
them in your code. You can dispose them in Finally block or you can use the "Using" clause,
so that they gets disposed when not required. If you are using SPContext then you need not
dispose the spsite or spweb objects.
3. Try writing your errors to SharePoint error logs (ULS Logs). Since it¶s a bad idea to fill-up
event log for your production environment.
4. Use SPQuery instead of foreach loop while retrieving Items from the list.
5. Deploy additional files used in your webpart to 12 hive. Use your solution package to
drop the files in 12 hive. Also, make sure that all the references (for e.g. Css or .js files) get
removed when the solution is retracted.
Also See : Best Practices to Improve Site Performance
Using SystemUpdate() will not create a new version and will also retain timestamps.
You can use SPSiteDataQuery when you need to extract data from more than one
list\library in your site colletcion. The data is extracted on the basis of the query you write
and is
returened as a Datatable. You can also specify the GUID for the lists\libraries you want to
query against.
This can be done by adding a new feature into SharePoint. You would need to use
customaction tag in your elements.xml file and will have to set various properties like
imageurl or UrlAction for your customaction. You can later add this feature into sharepoint
using stsadm install feature command.
To do this you can either create a new list type(again a feature) and use the listtype
number for the new list in your RegistrationType property of the Customaction. The
CustomAction will then show up only for the items of this list type. or You can create a new
content type and then use that content type's id in your cutsomaction to bind the custom
action to items of just that content type. Add the new content type to the list where you
need this customaction.
c *!
You would need to wrap the web application in a solution package in order to deploy it
in 12 hive or say ShraePoint. It is recommended to create a feature first, and then wrap
everything in a Solution package. See exampleDepoly a Custom aspx Page in SharePoint
c "/0 !+
"
1!21&2
You can either try to force execute timer jobs using execadmsvcjobs command or can
cancel the dpeloyment using stsadm command stsadm ±o cancaldeployment ±id {GUID}
command. The Id here would be GUID of the timer or deployment job. You can get the Id
from stsadm enumdeployment command. This will display all the deployments which are
process or are stuck with Error.
c
*!/
!
!
You can simply activate the SharePoint Publishing Feature for the Site, you want to
make publishing.
c !
Unlike site pages (for example, default.aspx), a custom application page is deployed
once per Web server and cannot be customized on a site-by-site basis. Application pages
are based in the virtual _layouts directory. In addition, they are compiled into a single
assembly DLL.
A good example of an Application Page is the default Site Settings page: every site has one,
and it's not customizable on a per site basis (although the contents can be different for
sites).
With application pages, you can also add inline code. With site pages, you cannot add inline
code.
c 3
An authentication system is how you identify yourself to the computer. The goal
behind an authentication system is to verify that the user is actually who they say they are.
Once the system knows who the user is through authentication, authorization is how the
system decides what the user can do.
c ,
You deploy your User Control either by a Custom webpart, which will simply load the
control on the page or can use tools like SmartPart, which is again a webpart to load user
control on the page. User Control can be deployed using a custom solution package for the
webapplication or you can also the control in the webpart solution package so that it gets
deployed in _controlstemplate folder.
c "
,
A WebPart renders faster than a User Control. A User Control in SharePoint is usually
loaded by a webpart which adds an overhead. User Controls however, gives you an
Interface to add controls and styles.
c
!#
When you create a new SharePoint site in a site collection, Windows SharePoint Services
provisions instances of files into the content database that resides on the file system. That
means if you create a new Site "xyz" of type Team Site(orTeam sIte Definition), an instance
of the Team Site Definition( Which resides on the File System), i.e. "xyz" gets created in the
Content database. So, When ASP.NET receives a request for the file, it first finds the file in
the content database. This entry in the content database tells ASP.NET that the file is
actually based on a file on the file system and therefore, ASP.NET retrieves the source of
the file on the file system when it constructs the page.
Customized :
A customized file is one in which the source of the file lives exclusively in the site collection's
content database. This happens When you modify the file in any way through the
SharePoint API, or by SharePoint Designer 2007,which uses the SharePoint API via RPC and
Web service calls to change files in sites. So, When the file is requested, ASP.NET first finds
the file in the content database. The entry in the database tells ASP.NET whether the file is
customized or uncustomized. If it is customized, it contains the source of the file, which is
used by ASP.NET in the page contraction phase.
c
Event receivers are classes that inherit from the SpItemEventReciever or
SPListEventReciever base class (both of which derive out of the abstract base class
SPEventRecieverBase), and provide the option of responding to events as they occur within
SharePoint, such as adding an item or deleting an item.
c
Since event receivers respond to events, you could use a receiver for something as
simple as canceling an action, such as deleting a document library by using the Cancel
property. This would essentially prevent users from deleting any documents if you wanted
to maintain retention of stored data.
c #"#" "
+
#!
You would create a event receiver for that list/library and implement the ItemDeleting
method. Simply, set: properties.Cancel= true and display a friendly message using
Properties.Message("How can u delete this... Its not your stuff!");
c ""
An asynchronous event occurs after an action has taken place, and a synchronous
event occurs before an action has take place. For example, an asynchronous event is
ItemAdded, and its sister synchronous event is ItemAdding
c # "!
"!"
To list a Web Part with Full Permissions within your Web Application while still
retaining a WSS_Minimal permission set for all other Web Parts, You need to create a
Custom policy file. This file will be then referenced in SharePoint Web.config file and will
allow your specific webpart to be of Full trust.
Steps :
1. Make a copy of the WSS_Minimal.Config file from the 12\Config folder and paste it into
the same folder renaming it to Custom_WSS_Minimal.Config. Now, edit the
Custom_WSS_Minimal.Config file using NotePad. Obtain the Public Key Token for the Web
Part assembly that you want to deploy, using the following command: sn ±Tp filename.dll.
Create a new entry in your Custom_WSS_Minimal.Config file for your WebPart. Save the
File.
Finally, Create a new TrustLevel element for your config file in the Web.Config called
Custom_WSS_Minimal that points to your custom file in the 12\config folder. Recycle the
Application Pool and You¶re Done.
c
When a new web applictaion is created via Central Admin, Windows SharePoint
Services creates a new Web application in IIS. Then the WSS, loads the custom HTTP
application and replaces all installed HTTP handlers and modules with Windows SharePoint
Services±specific ones. These handlers and modules essentially tell IIS to route all file
requests through the ASP.NET 2.0 pipeline. This is because most files in a SharePoint site
are stored in a Microsoft SQL Server database.
Examples:
Ans. A SharePoint Feature is a functional component that can be activated and deactivate at
various scopes throughout a SharePoint instances, scope of which are defined as
1. Farm level 2. Web Application level 3. Site level 4. Web level
Features have their own receiver architecture, which allow you to trap events such as when
a feature is Installing, Uninstalling, Activated, or Deactivated.
c "
"
We can create menu commands, Custom Actions,page templates, page instances, list
definitions, list instances,event handlers,webparts and workflows as feature.
strong>Q. How Do you bind a Drop-Down Listbox with a Column in SharePoint List ?
4$ You can get a datatable for all items in the list and add that table to a data set.
Finally, specify the dataset table as datasource for dropdown listbox.
5$ You can also use SPDatasource in your aspx or design page.
See Code example Binding Drop-Down with Sharepoint List data
c
The browser sends a DAV packet to IIS asking to perform a document check in.
PKMDASL.DLL, an ISAPI DLL, parses the packet and sees that it has the proprietary INVOKE
command. Because of the existence of this command, the packet is passed off to
msdmserv.exe, who in turn processes the packet and uses EXOLEDB to access the WSS,
perform the operation and send the results back to the user in the form of XML.
c '
c 6 *
!
*
You need to make some modification in the aspx file to display it in SharePoint
Context. Firstly, add the references for various sharepoint assemblies on the Page. Then
wrap the Code in PlaceHolderMain contentPlaceholder, so that it gets displayed as a content
page. Lastly, add a reference to SharePoint Master Page in aspx file and swicth it in Code
behind if needed. See Code Example at Display aspx Page in SharePoint context
c
!
!
c"#
$%&&'(()
"&
&
*
$%&&'(()
"
V
*
V
V *
&
V &
V +
&
V
&
V
, -
.
!
c"/
"&*c
&*&
c
0
,1c
,
*&
$*
#
$
Any customized page is parsed using safe mode processing. This parsing brings in security.
Safe mode processing guarantees that there is no inline script in the customized page. In
other words safe mode processing disallows in-line script because a hacker can mount
attack using in-line script. If you try to run in-line script on customized page you
will get error µCode blocks are not allowed in this file¶.
In case you still want to run in-line script in customized pages you need to specify
µAllowServerSideScript=true¶ in the µSafeMode¶ tag section in web.config file.
<SharePoint>
<SafeMode ... >
<PageParserPaths>
<PageParserPath
VirtualPath="/sites/MySite/SitePages/*"
IncludeSubFolders="true"
CompilationMode="Always"
AllowServerSideScript="true" />
</PageParserPaths>
</SafeMode>
</SharePoint>
Safe controls help us define which controls the customized pages will have. Customized
pages can only have controls which are defined in the web.config file in the µSafeControls¶
tag. For instance in the below code snippet we have defined that customized pages can use
controls from µMicrosoft.SharePoint.WebControls¶.
<SafeControls>
<SafeControl
Assembly="Microsoft.SharePoint"
Namespace="Microsoft.SharePoint.WebControls"
TypeName="*"
AllowRemoteDesigner="True" />
</SafeControls>
Ê
Ê
Show/Hide Answer
A µWebPart¶ control goes through various events and has a typical life cycle.
OnInit: - This is the initialization event and is the first event to occur.
Page.PreRenderComplete :- When all controls have executed the µOnPreRender¶ event this
event fires.
V Site provisioning
V Document management (check in/check out)
V Discussions
V Wikis, Blogs, RSS Feeds
V Basic workflow
V Custom lists
V Additional workflows
V Web content management (web publishing features)
V Records management
V Auditing
V Additional search such as people search
V My Sites (each user has their own personal site with public and private areas)
V Enterprise features such as Excel Services and BDC
3.3 What are safe controls, and what type of information, is placed in that
element in a SharePoint web.config file?
When you deploy a WebPart to SharePoint, you must first make it as a safe
control to use within SharePoint in the web.config file. Entries made in the
safe controls element of SharePoint are encountered by the
SharePointHandler object and will be loaded in the SharePoint environment
properly, those not will not be loaded and will throw an error. In the generic
safe control entry (this is general, there could be more), there is generally
the Assembly name, the namespace, the public key token numeric, the
typename, and the safe declaration (whether it is safe or not). There are
other optional elements.
"
Do read all blogs from Adrea Vala from
http://blogit.create.pt/blogs/andrevala/archive/2007/12/02/SharePoint-2007-
Deployment_3A00_-Overview.aspx
Ê
Regarding the development environment, there are two types of SharePoint projects:
V a projects, where everything is configured and developed directly in the
production environment;
V @ projects, where all the development and configuration is done in a
development environment, then possibly deployed to a testing environment, and finally deployed
to the production environment.
V a , when there is only one SharePoint Server in the farm (although there can
be additional SQL Servers);
V @ , when there are several SharePoint Servers, possibly with different server
roles, in the farm.
For Single Server ƛ Single Environment projects, which are the least common type, the developers don't
really need to be concerned about deployment since everything is done on the same server. But for the
other types of projects (Single Server ƛ Multiple Environment, Multiple Server ƛ Single
Environment and Multiple Server ƛ Multiple Environment) developers will need to deploy their work to the
servers.
Ê
@
In SharePoint, deployment means the necessary actions to install your software solution in a SharePoint
environment, whether that solution consists of web parts, custom web controls, event handlers, custom
web pages, or just master pages.
So, imagine you have created site columns and content types directly on the SharePoint UI, customized
some master pages using SharePoint Designer and installed a few custom web parts on your
Development Environment, and now you need to deploy this to the Testing Environment (and later on, to
the Production Environment). You can choose from a few different deployment methods:
V a
. You do it all over again in the Testing Environment, and later you will
repeat the procedure in the Production Environment. It's not hard to figure out this is a bad
practice: probably you won't be able to repeat the tasks in the exact same order as you did
before, and that might result in errors or in a Testing Environment that is not a replica of the
Development Environment. Also, that means the developers must have administration access in
all the environments, which is not always the case.
V (
. You perform a farm backup on the Development Environment
and restore it in the Testing Environment. Although commonly used, it's not the best practice
either: you must make sure all the assemblies, web.config modifications, and file system changes
are present in the destination environment before you restore the backup. Also, you might have
some problems if the environments are not in the same windows domain.
V
. You use SharePoint's content deployment paths and jobs. That can be a
good solution, but it has some limitations: unless you are deploying a whole site collection, you'll
need to make sure all the assemblies, web.configmodifications, and file system changes are
present in the destination environment before you restore the backup. Content deployment is
targeted at "contents" and not at "structure", although some of the SharePoint structures are
migrated with the contents. Also, both environments must be connected for automatic content
deployment to work. You have the option to export a site collection to a .CAB file and import it in
the destination environment using STSADM commands, but the same limitations apply.
V a
. You build SharePoint Features for all the objects you developed and
pack them in one or moreSharePoint Solutions. This is the recommended approach for structure
deployment, since it allows for multiple server farm deployment, allows the deployment of
assemblies, web.config modifications, files in file system folders as well as all SharePoint objects.
Ê
A Feature is a package composed of a set of XML files that describe Windows SharePoint Services
elements, which can be activated on a specific scope to help users accomplish a given task. To make it
easier to understand, I usually say that you should use a Feature when you need to add one or more
objects to SharePoint and want to allow users to easily enable or disable that option.
A Solution is a deployable and reusable package that can contain a set of Features, site definitions and
assemblies that you can apply to a site, and can also enable or disable individually. A Solution is
materialized in a solution file, which is a file with a CAB-based format with a extension.
V Install Features
V Install assemblies in the GAC
V Install assemblies to the BIN folder of a web application
V Add assembly descriptions to the web.config safe controls section
V Set Code Access Security configurations
V Install files in the template folder of SharePoint (usually C:\Program\Common
\Mrooft ar
\ rvrtnon\12\TEMPLATE)
V Install files in the root folder of SharePoint (usually C:\Program\Common
\Mrooft ar
\ rvrtnon\12)
V Install a site definition
A Solution is the only way to automatically execute a deployment of functionality to a SharePoint server
farm.
A Feature can be activated or deactivated in a specific scope, and there are four different scopes:
V È ƛ The elements will be deployed at the farm level. To activate or deactivate a farm-
scoped Feature, go to Central Administration, Operations section, and click on Manage Farm
Features in the Global Configuration group.
V Ê ƛ The elements will be deployed at the web application level.
To activate or deactivate a web application-scoped Feature, go to Central
Administration, Application Management section, and click on Manage Web Application
Features in the SharePoint Web Application Management group.
V a ƛ The elements will be deployed at the site collection level.
To activate or deactivate a site collection-scoped Feature, go to the root web site settings, and
click on Site Collection Features in the Site Collection Administrationgroup. You must be a site
collection administrator to see this setting.
V Êa ƛ The elements will be deployed at the web site level. To activate or deactivate a web
site-scoped Feature, go to the web site settings, and click on Site Features in the Site
Administration group. You must have ManageWebpermissions (for instance, being a site
administrator) to see this setting.
vach type of element can be deployed to one or more of these scopes. When describing each element
type, I will specify to which scopes they can be deployed to.
To create a Feature you must create a XML file named feature.xml which contains all the general
configurations for the Featureand the references to all the files that describe the Elements contained in
the Feature. Below is an example of a faturm file that uses all possible attributes, just for
demonstration purposes. Required attributes are printed in bold.
mvron="1"no
ng="utf-8"
eaturexmlns="http://schemas.microsoft.com/sharepoint/"
="AB30188E-6-4380-899-4643E2"
cope="ite"
Tt="Myatur"
rton="Myaturnu
vramnt"
ron="1"
Crator="An
réaa"
outonI
="253188E-65A-433B-899-BA9843E25"
Imagr="/_ayout/Myatur/MyaturIong"
ImagrAtTt="MyaturIon"
n="ALE"
Atvatnfaut="ALE"
A ayorInta="ALE"
AutoAtvatInCntraA
mn="ALE"
urour="TE"
fautour="Myour"
vrAmy="Myaturvr,ron=1,Cutur=Nutra,
PuyTokn=3f5
f551a199"
vrCa="MyaturvrMyvrCa"
Atvatonn
n
Atvatonn
nyaturI
="C3829C4-E85-4CE-98-
BE38AC5"/
/Atvatonn
n
EmntManft
EmntManftLoaton="MyEmnt1m"/
EmntManftLoaton="MyEmnt2m"/
EmntManftLoaton="MyEmnt3m"/
EmntLoaton="My1g"/
EmntLoaton="My2g"/
/EmntManft
Prort
Prortyy="MyProrty"au="Myau"/
/Prort
/eature>
ë To make things easier when creating these files in Visual Studio 2005 (or later), you can use
the àss.xs schema file, included with SharePoint (usually in C:\Program\Common
\Mrooft ar
\ rvrtnon\12\TEMPLATE\XML), to enable Intellisense.
Site Column Features
a
This post is about developing features to create site columns in a SharePoint site. Check the first
post SharePoint 2007 Deployment: Overview for an introduction and the series index.
a
As I mentioned previously in the post SharePoint 2007 Deployment: Creating and Using Features, to build
a feature you need to create the following files:
The feature manifest file contains the generic information about the feature package, and
the element manifest files contain the information about each specific type of element that makes up
the feature. Since I already explained all the possible contents of the feature manifest file in the above
mentioned post, I will focus this one the element manifest that allows the creation of site
columns in a SharePoint site.
You can then place these two files inside a Solution following the instructions in the post SharePoint
2007 Deployment: Creating Solutions, to provide an easy way to deploy the feature (or upgrade it).
a
Just to keep everything clear, I'm going to give a brief explanation about the concept of site columns.
Site columns are reusable column definitions, which means that they are exactly the same as a regular
list column but do not belong to any single list. A site column exists in the context of a web site
(organized in groups, in the site column gallery) and can be used in lists and content types in that web
site or its child web sites.
One can create new site columns or edit the existing ones following the steps below:
a
The scopes to which a feature can be deployed, are dictated by the types of elements included in it. A
feature with site column elements can only be deployed to a or Êa scopes.
mvron="1"no
ng="utf-8"
aturmn=" tt:// mamrooftom/ aront/"
I
="512A-AA-463-8B8-C49B119183"
Tt="MytCoumnatur"
rton="A
MytCoumn"
o="t"
ron="1"
EmntManft
EmntManftLoaton="tCoumnm"/
/EmntManft
/atur
v@
The element manifest file can have any name you wish (in this example it's
called tCoumnm), but it's root element must be
Emnt. Inside this root element, you
can place any number of feature element descriptions. In this example I will present the use of
the
element which is used to deploy Site Columns.
n="ALE"
a
ny="ALE"
o Inayorm="TE"
o InE
torm="TE"
o InLtttng="TE"
o InN orm="TE"
o Inrontory="TE"
o In orm="TE"
rou="CutomCoumn"
/
/Emnt
This example creates a site column, named ëÈ , of type a ë. See below a short
explanation of the used attributes:
V - This is the unique identifier of this site column. It will be used to reference this site column
when including it in a content type or attaching it to a list.
V ë pe - This attribute specifies the type of data stored in the site column. It can have one of the
following values:
o AayEvnt: All day event flag, used in calendar lists.
o Atta mnt: Stores the URL of attachments.
o Booan: Specifies a Yes/No field.
o Cauat
: Specifies that this field's value is calculated based on other columns'
values.
o C o: Specifies a Choice (menu to choose from) field with a pre-defined set of
values.
o Comut
: Specifies a field whose value depends on another field's value.
o ContntTyI
: Contains a Content Type ID value.
o Countr: Used to hold the internal ID's for each item.
o Currny: Specifies a field that stores a currency value (its format depends on the
locale).
o atTm: Specifies a Date and Time field.
o : Contains a file (used in document libraries).
o r
C o: Specifies a rating scale (used in surveys).
o u
: Specifies a field that holds a unique identifier.
o Intgr: Specifies a number field that holds integer values only.
o Looku: Specifies a Lookup field, which is similar to the Choice field except the
available choices are retrieved from another list.
o LookuMut: Specifies a Lookup field that allows multiple selections.
o Mo
tat: Specifies a field that contains content approval status.
o MutC o: Specifies a Choice field that allows multiple selections.
o Not: Specifies a Multiple Lines of Text field.
o Numr: Specifies a Number field, that can hold floating-point values.
o Pagarator: Specifies a page separator (used in surveys).
o urrn: Used to mark an event as recurrent in a calendar list.
o Tt: Specifies a Single Line of Text field.
o T ra
In
: Specifies the correlation ID in a threaded conversation (used in
discussion lists).
o T ra
ng: Used in the creation and display of threaded discussion-like views.
o L: Specifies a Hyperlink or Picture field.
o r: Specifies a Person or Group field.
o rMut: Specifies a Person or Group field that allows multiple selections.
o Êorkfo EvntTy: Contains the type of workflow history event (used in workflow
history list).
o Êorkfo tatu: Contains the workflow status (used in lists that have associated
workflows).
V ëitle - This is the name of the field shown in the interface, and it can be changed by the user.
V ×ame - (optional) This is the internal name of the field, and is guaranteed to never change during
the lifetime of the field. It is automatically generated from the display name of the field, and the
spaces and special characters are escaped.
V tatic×ame - (optional) This is automatically set to the same value as the internal name, but
can be changed programmatically (not through the interface though).
V ispla ×ame - (optional) This is the same as the Title property.
V escription - (optional) This is the description for the field. SharePoint displays this text in
new/edit forms below the data entry control.
V equire - (optional) Specifies if the field is mandatory. Default value is ALE.
V @axLength - (optional) Specifies the maximum number of characters allowed for this field.
V þien - (optional) Specifies that the field should be completely hidden from the interface. If
TRUv, this field will not be shown on views or forms. Default value is ALE.
V eanl - (optional) Specifies that the field should be read-only, which means it appears in
views but will be hidden from new/edit forms. Default value is ALE.
V hoànispla orm - (optional) Specifies that the field should be shown in display forms.
Default value is TE.
V hoànEitorm - (optional) Specifies that the field should be shown in edit forms. Default
value is TE.
V hoànListettings - (optional) Specifies that the field should be shown in the list settings
screen. Default value is TE.
V hoàn×eàorm - (optional) Specifies that the field should be shown in new forms. Default
value is TE.
V hoànVersionþistor - (optional) Specifies that the field should be shown in the version
history of an item. Default value isTE.
V hoànVieàorms - (optional) Specifies that the field should be shown in view forms. Default
value is TE.
V Kroup - (optional) Specifies the name of the group that contains the site column.
The Choice field has a few specific issues that are worth mentioning:
V The ë pe attribute must be set to C o.
V The ormat attribute is used for several purposes, but in choice fields, it defines the type of
control used to select the option. Possible values are ro
o n (default) and a
oButton.
V The attribute illnChoice specifies if the user can add choices to the column.
V The
faut child element specifies which of the choices is pre-selected in the control as
default.
V The
CICE child element contains all the possible value options, each in its
own
CICE child element. Beware that you must use capital letters for these elements,
otherwise the field will not contain any of the choices.
The Multiple Lines of Text field also has some specific attributes:
I="{59341-14f-489-9
5-a683
a924"
Ty="Numr"
Nam="My_2_Numr"
tatNam="My_2_Numr"
ayNam="MyNumr"
ur
="ALE"
Mn=""
Ma="1"
ma=""
Prntag="ALE"
rou="CutomCoumn"
/
The Lookup field is the only field type that cannot be created with a simple feature such as this one.
The cause for this is the fact that this type of field references a column of a list using the list's ID, and a
list's ID is dynamically generated when a list is created.
This means that there is no way one can predict what will be the ID of the list referenced by
the Lookup field when the feature is developed. This value is only known when the feature is activated
in a specific web site.
For that reason, the steps to create a feature for this type of site column will be the subject of one of the
next posts of the series.
"!"7
Feature Stapling
a
This post is about developing features that associate other features to an existing site definition. This is
one of the most powerful types of feature since it allows you to add new functionality to existing site
definitions. Check the first post SharePoint 2007 Deployment: Overview for an introduction and the series
index.
a
As I mentioned previously in the post SharePoint 2007 Deployment: Creating and Using Features, to build
a feature you need to create the following files:
The feature manifest file contains the generic information about the feature package, and
the element manifest files contain the information about each specific type of element that makes up
the feature. Since I already explained all the possible contents of the feature manifest file in the above
mentioned post, I will focus this one the element manifest that allows the feature stapling (feature
site template association).
You can then place these two files inside a Solution following the instructions in the post SharePoint
2007 Deployment: Creating Solutions, to provide an easy way to deploy the feature (or upgrade it).
V The feature (or features) you wish to associate (that is, to staple) to a site definition;
V The feature that performs the association (the stapler).
The first one can be any feature with scope Site or Web. The second is the one Iƞm presenting in this
post.
a
The scopes to which a feature can be deployed, are dictated by the types of elements included in it. A
feature with feature site template association elements can be deployed to a , Ê
or È scopes.
V
V
2
0&
*
3
&
*
2
4
fauta
4
5
+
3
&
*
6 65
| |
.
5
&
1
3
2
0
%
0
0
&
* /
&
*2
&
*
&
*66
.
+
&
*
+
7
0
0
NETXML
8
È
Depending on where a Onet.xml file is located and whether it is part of a site definition or a Web
template, the markup in the file does some or all of the following:
V apecify the Web-scoped and site collection-scoped Features that are built-in to Web sites created
from the site definition or Web template.
V apecify the lists types, pages, files, and Web Parts that are built-in to Web sites created from the
site definition or Web template.
V Define the top and side navigation areas that appear on the home page and in list views for a site
definition.
V apecify the list definitions that are used in each site definition and whether they are available for
creating lists in the UI.
V apecify document templates that are available in the site definition for creating document library
lists in the UI, and specify the files used in the document templates.
V Define the base list types from which default aharePoint Foundation lists are derived. (Only the
global Onet.xml file serves this function. You may not define new base list types.)
V apecify aharePoint Foundation components.
V Define the footer section used in server e-mail.
a
Developers who write custom code with the aharePoint object model will encounter common issues
related to performance, extensibility, and scalability. This article is a resource for developers who are
working to troubleshoot and improve the performance of existing aharePoint applications or who are
writing new aharePoint applications. In both cases, it is important to understand how to make the
aharePoint object model work efficiently, and how to apply general programming techniques (such as
caching and threading) to the aharePoint platform specifically. This information can make it easier to
design your applications correctly, find and fix problem areas in your code, and avoid known pitfalls of
using the aharePoint object model.
The following areas reflect the most common general concerns encountered by aharePoint developers:
This article addresses all but the last of these issues. For guidance on disposing of aharePoint objects,
see Best Practices: Using Disposable Windows aharePoint aervices Objects.
Additionally, we recommend that you read the following orientation topics as good starting points for
using the aharePoint object model:
Va
aching is one good way to improve system performance. However, you must weigh the benefits of
caching against the need for thread safety. Additionally, you should not create certain aharePoint objects
within event receivers because this will cause performance problems related to excessive database calls.
This section describes these common areas of concern so that you can learn ways to optimize your use of
aharePoint objects and data.
Caching Data and Objects
Many developers use the Microsoft .NET Framework caching objects (for
example, a
) to help take better advantage of memory and increase
overall system performance. But many objects are not "thread safe" and caching those objects can cause
applications to fail and unexpected or unrelated user errors.
ë
!
"
!
#
!
&'' (
You might try to increase performance and memory usage by caching a
objects
that are returned from queries. In general, this is a good practice; however,
the a
object contains an embedded a
object that is not thread safe and
should not be cached.
The guidance in the following section describes how you can prevent multiple threads from attempting to
read the same cached object.
You might not be aware that your code is running in a multithreaded environment (by default, Internet
Information aervices, or IIa, is multithreaded) or how to manage that environment. The following example
shows the code some developers use to cache Microsoft.aharePoint.aPListItemollection objects.
(
VB
F
sacript
opy
j
!"#$ !
%&
''%%
(
(
Although the use of the cache in this example is functionally correct, because the AaP.NET cache object is
thread safe, it introduces potential performance problems. (For more information about AaP.NET caching,
see the ache class.) If the query in the preceding example takes 10 seconds to complete, many users
could try to access that page simultaneously during that amount of time. In this case, all of the users
would run the same query, which would attempt to update the same cache object. If that same query runs
10, 50, or 100 times, with multiple threads trying to update the same object at the same time³especially
on multiprocess, hyperthreaded computers³performance problems would become especially severe.
To prevent multiple queries from accessing the same objects simultaneously, you must change the code
as follows.
VB
sacript
opy
j!
)*+,)
j
+*+
!"#$ !
%&
''%%
(
(
(
You can increase performance slightly by placing the lock inside the f(oLtItm==nu code
block. When you do this, you do not need to suspend all threads while checking to see if the data is
already cached. Depending on the time it takes the query to return the data, it is still possible that more
than one user might be running the query at the same time. This is especially true if you are running on
multiprocessor computers. Remember that the more processors that are running and the longer the query
takes to run, the more likely putting the lock in the f( code block will cause problems. If you want to
make absolutely sure that another thread has not created oLtItm before the current thread has a
chance to work on it, you could use the following pattern.
VB
sacript
opy
j!
)*+,)
j
+*+
--. !
,
"
!!!
,
,
/!+%
0
1
!"#$ !
%&
''%%
(
(
(
(
If the cache is already populated, this last example performs as well as the initial implementation. If the
cache is not populated and the system is under a light load, acquiring the lock will cause a slight
performance penalty. This approach should significantly improve performance when the system is under a
heavy load, because the query will be executed only once instead of multiple times, and queries are
usually expensive in comparison with the cost of synchronization.
The code in these examples suspends all other threads in a critical section running in IIa, and prevents
other threads from accessing the cached object until it is completely built. This addresses the thread
synchronization issue; however, the code is still not correct because it is caching an object that is not
thread safe.
!
j!
)*+,)
j
#
#
+*+
#
#
#
!"#$ !
#
%2
#
%&
'
#
'%%
(
(
(
V They incur significant additional roundtrips to the database. (One write operation can result in up
to five additional roundtrips in each event receiver.)
(
j !!
/.!j!j!j!
/,j!j!%34!
/3,%5j3
,%j!j!%
%26"47 j!j!%
--5j!
%
(
(
(
!
Vsing SPOtemEventProperties
If you do not apply this fix in your code, when you call V
on the new instance, you must invalidate
it with the
method in the appropriate child class ofa
(
(for
example, a
or a
).
È
When folders and lists grow in size, custom code that works with them needs to be designed in ways that
optimize performance. Otherwise, your applications will run slowly and even cause timeouts to occur. The
following recommendations for addressing performance concerns while working with large folders and
lists are based on the test results reported in ateve Peschka's white paper, Working with Large Lists in
Office aharePoint aerver 2007.
a
selects all items from all subfolders, including all fields in the list. Use the following
alternatives for each use case.
o
Use a!
"a#
$
%instead. Apply filters, if appropriate, and
specify only the fields you need to make the query more efficient. If the list contains more
than 2,000 items, you will need to paginate the list in increments of no more than 2,000
items. The following code example shows how to paginate a large list.
!
The following example shows how to enumerate and paginate a large list.
o !
Accessing the methods and properties that are listed in the left column of the following table will
enumerate the entire a
collection, and cause poor performance and throttling for
large lists. Instead, use the alternatives listed in the right column.
'
a
*
(
a
a
a a Create an a object to retrieve only the items you want.
a Create an a object (specifying the ) to retrieve only the items
a (
$a!
)a&' )a Perform a paged query by using a and reorder the items within each pag
&'%
a
a
ëa
(
'
)
,
" -
(
!
ateve Peschka's white paper Working with Large Lists in Office aharePoint aerver 2007 describes
an efficient approach to retrieving list data in Office aharePoint aerver 2007 by using
the a
*
class. a
*
provides an automatic caching
infrastructure for retrieving list data. The!
(#
method
of a
*
takes an a#
object as a parameter, and then checks its cache
to determine whether the items already exist. If they do, the method returns the cached results. If
not, it queries the list and stores the results in a cache. This approach works especially well when
you are retrieving list data that does not change significantly over time. When data sets change
frequently, the class incurs the performance cost of continually writing to the cache in addition to
the costs of reading from the database. onsider that the a
*
class uses
the site collection object cache to store data. This cache has a default size of 100 MB. You can
increase the size of this cache for each site collection on the object cache settings page for the
site collection. But this memory is taken from the shared memory available to the application pool
and can therefore affect the performance of other applications. Another significant limitation is
that you cannot use the a
*
class in applications based on Windows
Forms. The following code example shows how to use this method.
!
Ò. Whenever possible, acquire a reference to a list by using the list's GUID or URL as a key.
*
+
When you delete multiple versions of a list item, use the DeleteByID method; do not use
the Delete method. You will experience performance problems if you delete
eacha
+
object from an a
+
object. The
recommended practice is to create an array that contains the ID properties of each version and then
delete each version by using the aÈ
+
( method. The following
code examples demonstrate both the approach that is not recommended and the recommended
approach to deleting all versions of the first item of a custom list.
(
!
If you are deleting versions of items in a document library, you can use a similar approach by retrieving
the a
È
+
property, as in the following code example.
!
Deleting each version of a list item in a document library by using the SPFileVersionCollection.DeleteByOD
method
a
V
You might not be aware that you need to write your code to be scalable so that it can handle multiple
users simultaneously. A good example is creating custom navigation information for all sites and subsites
on each page or as part of a master page. If you have a aharePoint site on a corporate intranet and each
department has its own site with many subsites, your code might resemble the following.
j 2
/
;!&&3
!
?% !!%%3&jj
%
!"
33%$3
&&33
(
"
%
j
(
(
(
j &&333
!
3 33%3
!"
--%%
%%
&&3 3
(
"
3D
3%
j
(
(
(
While the previous code disposes of objects properly, it still causes problems because the code iterates
through the same lists over and over. For example, if you have 10 site collections and an average of 20
sites or subsites per site collection, you would iterate through the same code 200 times. For a small
number of users this might not cause bad performance. But, as you add more users to the system, the
problem gets worse, as shown in Table 2.
,
Users Iterations
] 2
5 ]
] 2
25 5
Although the code executes for each user that hits the system, the data remains the same for each user.
The impact of this can vary depending on what the code is doing. In some cases, repeating code might
not cause a performance problem; however, in the previous example the system must create a OM
object (aa
or a
objects are created when retrieved from their collections), retrieve data from
the object, and then dispose of the object for each item in the collection. This can have a significant
impact on performance.
How to make this code more scalable or fine-tune it for a multiple user environment can be a hard
question to answer. It depends on what the application is designed to do.
You should take the following into consideration when asking how to make code more scalable:
V Is the data static (seldom changes), somewhat static (changes occasionally), or dynamic (changes
constantly)?
V Is the data the same for all users, or does it change? For example, does it change depending on
the user who is logged on, the part of the site being accessed, or the time of year (seasonal
information)?
V Is the data easily accessible or does it require a long time to return the data? For example, is it
returning from a long-running database query or from remote databases that can have some
network latency in the data transfers?
How you answer the previous questions will determine in which of several ways you can make your code
more scalable and handle multiple users. The intent of this article is not to provide answers for all of the
questions or scenarios but to provide a few ideas that you can apply to your specific needs. The following
sections offer areas for your consideration.
If your data is static, you can set up the cache to load the data only one time and not expire until the
application is restarted, or to load the data once per day to ensure data freshness. You can create the
cache item when the application starts, when the first user session starts, or when the first user tries to
access that data.
If your data is somewhat static, you can set up the cached items to expire within a certain number of
seconds, minutes, or hours after the data is created. This enables you to refresh your data within a
timeframe that is acceptable to your users. Even if the data is cached for only 30 seconds, under heavy
loads you will still see improved performance because you are running the code only one time every 30
seconds instead of multiple times per second for each user who hits the system.
aecurity trimming is another issue to consider whenever you cache data. For example, if you cache items
as you iterate through a list, you may get only a subset of the data (the data that the current user can
see), or if you use a
object to cache all of the items in a list, you have no easy way of
applying security trimming to users who belong to groups that can see only a subset of the data. For
more information about storing security trimmed data in caches, see the rossListQueryache class.
In addition, ensure you consider the issues described earlier in aching Data and Objects.
Think about how your cached data will be used. If this data is used to make run-time decisions, putting it
into a a
or
object might be the best way to store it. You can then query those
objects for the data to make run-time decisions. If the data is being used to display a list, table, or
formatted page to the user, consider building a display object and storing that object in the cache. At run
time, you need only retrieve the object from the cache and call its render function to display its contents.
You could also store the rendered output; however, this can lead to security issues and the cached item
could be quite large, causing increased page swapping or memory fragmentation.
Depending on how you set up your aharePoint site, you might have to address certain caching issues
differently. If your data must be the same on all servers at all times, then you must ensure that the same
data is cached on each server.
One way to ensure this is to create the cached data and store it on a common server or in a Microsoft aQL
aerver database. Again, you must consider how much time it takes to access the data and what security
issues can arise from storing the data on a common server.
You can also create business-layer objects that cache data on a common sever, and then access that data
by using various interprocess communications that are available in networking objects or APIs.
Va#
aPQuery objects can cause performance problems whenever they return large result sets. The following
suggestions will help you optimize your code so that performance will not suffer greatly whenever your
searches return large numbers of items.
An a#
object without a value for
will perform poorly and fail on large lists.
apecify a
between 1 and 2000 and, if necessary, page through the list.
If you query on a field that is not indexed, the query will be blocked whenever it would result in a
scan of more items than the query threshold (as soon as there are more items in the list than are
specified in the query threshold). aet a#
to a value that is less than the query
threshold.
V If you know the URL of your list item and want to query by È
,
use PÊtLtItm(trngtrr,trngf
1,aramtrng[]
f
instead.
V
When you inherit and override controls in the *a
namespace,
remember that aharePoint Web controls are templated controls. Unlike Microsoft AaP.NET Web controls,
they are defined and rendered with templates instead of with the
method.
Instead of having a thick
method that uses the new operator to create child
controls, perform most child control creation and rendering by using the rendering templates that are
referenced in the
,
,
,
,
and
properties of the aharePoint Web control. aharePoint Web controls
do inherit the
method, but that method should typically do little or nothing
beyond calling the parent control's
method and perhaps a bit of "final polish"
rendering, such as assigning default values to child control properties in New mode or assigning the
current values in Edit mode.
For an example, see Walkthrough: reating a ustom Field Type. In addition, see
the Microsoft.aharePoint.Webontrols namespace.
-
Design your timer jobs so that they consist of small, manageable pieces. Because administrators and other
events, such as system restarts, can stop timer jobs, you can minimize the amount of rework after any
interruption by breaking timer jobs into small pieces of work.
To ensure that your aharePoint system performs at its best, you need to be able to answer the following
questions about the code you write:
V Does my code work as efficiently for 1,000 users as it does for 10 users?
!
a a
Virtual Provider is nothing but HTTPHandler and HTTPModule to identify from where to
display pages (from content database or from file system)
) allow reusable pieces of functionality to be created and deployed to other
sites,without modifying site templates.It is always better to deploy a feature in new site
instead ofdirectly embedding mountains of complex XML.Using Features, you can do
everything from adding a link to the Site Settings page to creating a complete, fully
functioning Project Management suite that can be added to any SharePoint site.Features are
organized in folders under the Features directory located under 12 hives; Where SharePoint
Server 2007 puts all of its system files, at the following path: %SystemDrive%\Program
Files\Common Files\Microsoft Shared\web server extensions\12. The two files that are used
to define a feature are the feature.xml and Elements.xml .The feature XML file defines the
actual feature and will make SharePoint aware of the installed feature. It usually identifies
the Feature itself and its element manifest file and sets the Feature scope to Web site.
Elements.xml file identifies the assembly, class, and method to implement in feature.
allow you to package Features in a cabinet (.cab) file and define important
metadata about those Features. After a Solution is installed on a server in the farm, you can
then use SharePoint¶s Solution management features to automate the deployment of that
Solution to other sites within the farm.
The solution manifest (always called manifest.xml) is stored at the root of a solution file.
This file defines the list of features, site definitions, resource files, Web Part files, and
assemblies to process. It does not define the file structure²if files are included in a solution
but not listed in the manifest XML file, they are not processed in any way.
Because the solution file is essentially a .cab file, use the makecab.exe tool to create the
solution package. The makecab.exe tool takes a pointer to a .ddf file, which describes the
structure of the .cab file. The format of a .ddf file is, declare a standard header and then
enumerate, one file per line, the set of files by where they live on disk, separated by where
they should live in the .cab file.
Features are a method for developers to package customisations and deploy them to the
SharePoint portal. They can then be activated and deactivated at the Site Collection level.
Solutions are a way to bundle features together for deployment.
$ Represents a link, toolbar button, menu item, or any control that can be
added to a toolbar or menu that appears in the UI. You define custom actions by using a
custom action element within a feature definition file. You can bind custom actions to a list
type, content type, file type, or programmatic identifier (ProgID). For more information, see
Custom Action Definitions.
$ A file or collection of file instances that define the location where the files are
installed during site creation. Modules are frequently used to implement a Web Part Page in
the site. You can define modules by using a module element within a feature definition file.
For more information, see Modules.
$ A Web site hosted in a virtual URL. A SharePoint site is a place for
collaboration, communication, or content storage. Depending on your business needs, you
can create sites such as team sites, blog sites, wiki sites, and others. You can customize a
site's appearance, users, user permissions, galleries, and site administration by using the
Site Settings administration pages.
$ A collection of SharePoint sites that share common
administration pages and site settings. Site collections allow you to share content types, site
columns, templates, and Web Parts within a group of SharePoint sites.
"$ A group of Office SharePoint 2007 servers that share the same
configuration database. All site content and all configuration data is shared for all front-end
Web servers in a server farm.
" $ A set of files that includes a master XML configuration file that is stored on
all front-end Web servers. A site definition provides the basic blueprint for how sites look,
what lists they include, their default navigational structures, and so on. For more
information, see Working with Site Templates and Definitions.
($A group of files (CSS, images) that allow you to define the appearance (look and
feel) of Web pages. Themes in ASP.NET 2.0 and themes in SharePoint Products and
Technologies work in the same way. Themes are used to help organizations to brand their
portals and team sites. Office SharePoint Server 2007 includes a set of predefined themes.
However, as a developer, you can create custom themes for your company. For more
information, see How to: Customize Themes.