Thursday, 23 August 2012
Wednesday, 18 July 2012
Bind lookup field data to the dropdownlist
if (spListItem["LookupField"]
!= null)
{
SPFieldLookupValue spv = new
SPFieldLookupValue(spListItem["LookupField"].ToString());
string lookupValue = spv.LookupValue;
dropdownlist1.SelectedIndex
= spv.LookupId;
}
|
To bind field values to the dropdownlist:
dropdownlist1.SelectedValue = spListItem["Field1"].ToString();
|
Tuesday, 12 June 2012
Monday, 11 June 2012
Monday, 14 May 2012
How to connect to the Oracle database using Business Connectivity Services (BCS) in SharePoint 2010
Introduction:
Business Connectivity Services (BCS) is a new service introduced with SharePoint 2010 to allow SharePoint sites to connect to and manipulate external data. SharePoint 2007 had a similar facility in the form of Business Data Catalog (BDC) which made external data available within its site. However, a major problem with BDC was the difficulty in creating solutions as there was no support in the 2007 designer. Most BDC solutions were simply for accessing external data, manipulating external data sources was extremely difficult.
With SharePoint 2010, BCS ships with out-of-box features such as solutions, services, and tools which may connect to external data an easy task. Whether you want to retrieve Outlook contacts in a list offline or edit the contents of your document file or share your excel sheet online or reuse data from dynamic InfoPath forms or just update your business presentation, BCS enables deep content sharing, editing and integration in SharePoint 2010 with SharePoint Designer and Visual Studio tools. To connect to the SQL database we can use either SharePoint designer (where we can connect directly to the SQL or using WCF or through .Net Assembly) or using Visual Studio (BDC Model). In case of connecting to the Oracle database we don't have direct option in the SharePoint designer, so we can use BCS Meta Man to create an external content type.
Prerequisites:
I. A local installation of either SharePoint Foundation 2010 or SharePoint Server 2010,
ii. Oracle Client (Version: 10g),
iii. Visual Studio 2010 and
iv. BCS Meta Man.
Oracle Database:
Table Name: HR.CUSTOMERS
Note:
In the above table CUSTOMER_ID is the Primary Key.
Creating a BCS External Content Type:
Steps Involved:
The following steps should be followed to create a BCS External Content Type using Visual Studio 2010.
v. Open Visual Studio 2010.
vi. Go to File => New => Project.
vii. Select Empty SharePoint Project under installed template category SharePoint 2010 and name it as BCSUsingOracleDatabase.
viii. Click OK.
ix. Check "Deploy as a farm solution".
x. Click Finish.
xi. Right click the Solution Explorer and add a New Item.
xii. Select BCSMetaMan under installed template category Lightning Tools and name it as BCSMetaManForOracle.
xiii. Click ADD.
xiv. Add System.Data.OracleClient reference to your project.
xv. Connect to the Oracle Database.
xvi. Create an External Content Type Using BCS Meta Man.
xvii. Build the Project.
xviii. Once it is build successfully, Deploy the project.
Configure Business Data Connectivity access rights:
I. Go to Central Administration -> Application Management -> Manage Service Applications.
ii. Click on Business Data Connectivity Service.
iii. In the top Ribbon click on Manage.
iv. In Service Application Information check the External Content Type HR_CUSTOMERS.
v. In the top Ribbon click the Site Object Permissions.
vi. Site Object Permissions wizard will pop up add the account (Group or Users) and assign the permissions.
Creating an External List in the SharePoint Site:
I. Open the SharePoint Site.
ii. Go to Site Actions => More Options.
iii. On the Create Wizard, from the Installed Templates Select List.
iv. In the List Type select External List and click Create.
v. Enter the Name as BCS for OracleDB and choose the External Content Type as shown below.
vi. Click OK.
vii. External List is created successfully.
Testing:
Creating a new item:
I. Click on Add new item option in the ribbon.
ii. Enter the values as shown below.
iii. Click OK.
iv. New item will be created in the SharePoint External List.
Update in the Oracle DB:
I. Go to Oracle รข€“ OraClient10g home => Application Management => SQL Plus.
ii. Enter the User Name, Password and Host String as shown below.
iii. Select the table to see the changes as shown below.
iv. A new item has been added to the HR.CUSTOMERS table.
Summary:
Thus an external content type is created for oracle database using BCS Meta Man and an external list is created based on that external content type to display the Oracle data.
Business Connectivity Services (BCS) is a new service introduced with SharePoint 2010 to allow SharePoint sites to connect to and manipulate external data. SharePoint 2007 had a similar facility in the form of Business Data Catalog (BDC) which made external data available within its site. However, a major problem with BDC was the difficulty in creating solutions as there was no support in the 2007 designer. Most BDC solutions were simply for accessing external data, manipulating external data sources was extremely difficult.
With SharePoint 2010, BCS ships with out-of-box features such as solutions, services, and tools which may connect to external data an easy task. Whether you want to retrieve Outlook contacts in a list offline or edit the contents of your document file or share your excel sheet online or reuse data from dynamic InfoPath forms or just update your business presentation, BCS enables deep content sharing, editing and integration in SharePoint 2010 with SharePoint Designer and Visual Studio tools. To connect to the SQL database we can use either SharePoint designer (where we can connect directly to the SQL or using WCF or through .Net Assembly) or using Visual Studio (BDC Model). In case of connecting to the Oracle database we don't have direct option in the SharePoint designer, so we can use BCS Meta Man to create an external content type.
Prerequisites:
I. A local installation of either SharePoint Foundation 2010 or SharePoint Server 2010,
ii. Oracle Client (Version: 10g),
iii. Visual Studio 2010 and
iv. BCS Meta Man.
Oracle Database:
Table Name: HR.CUSTOMERS
Note:
In the above table CUSTOMER_ID is the Primary Key.
Creating a BCS External Content Type:
Steps Involved:
The following steps should be followed to create a BCS External Content Type using Visual Studio 2010.
v. Open Visual Studio 2010.
vi. Go to File => New => Project.
vii. Select Empty SharePoint Project under installed template category SharePoint 2010 and name it as BCSUsingOracleDatabase.
viii. Click OK.
ix. Check "Deploy as a farm solution".
x. Click Finish.
xi. Right click the Solution Explorer and add a New Item.
xii. Select BCSMetaMan under installed template category Lightning Tools and name it as BCSMetaManForOracle.
xiii. Click ADD.
xiv. Add System.Data.OracleClient reference to your project.
xv. Connect to the Oracle Database.
-
Go to Tools => Connect to Database.
- Add Connection wizard will pop up.
- Choose the Data Source as Oracle Database (Oracle Client).
-
Enter the Server Name, User Name and Password as shown below.
-
Click on Test Connection.
- Click OK.
-
In the Server Explorer you can view the Oracle Database as shown below.
xvi. Create an External Content Type Using BCS Meta Man.
-
You will find the BCS Meta Man menu item in the menu bar.
- Click on BCS Meta Man - > BCS Meta Man Data Source Explorer.
- Click on the "Add Connection" button of the data source explorer.
- In the Connection Dialog choose the Data Source as Oracle.
- Enter the Database Name, User Name and Password.
-
Click Connect.
-
Oracle Database will be displayed with all tables.
- Drag and drop the HR.CUSTOMERS table in the BCS Meta Man design surface.
-
In the Model Type wizard select .Net assembly and click OK.
-
Entity Creation wizard will pop up, click next.
-
By default CUSTOMER_ID will be selected as identifier.
- Click Next.
-
Select all the methods that are available and click Generate.
-
BCS Meta Man will add new files to the project which contain generated C#
code.
-
You'll also see the External Content Type on the design surface as shown
below.
xvii. Build the Project.
xviii. Once it is build successfully, Deploy the project.
Configure Business Data Connectivity access rights:
I. Go to Central Administration -> Application Management -> Manage Service Applications.
ii. Click on Business Data Connectivity Service.
iii. In the top Ribbon click on Manage.
iv. In Service Application Information check the External Content Type HR_CUSTOMERS.
v. In the top Ribbon click the Site Object Permissions.
vi. Site Object Permissions wizard will pop up add the account (Group or Users) and assign the permissions.
Creating an External List in the SharePoint Site:
I. Open the SharePoint Site.
ii. Go to Site Actions => More Options.
iii. On the Create Wizard, from the Installed Templates Select List.
iv. In the List Type select External List and click Create.
v. Enter the Name as BCS for OracleDB and choose the External Content Type as shown below.
vi. Click OK.
vii. External List is created successfully.
Testing:
Creating a new item:
I. Click on Add new item option in the ribbon.
ii. Enter the values as shown below.
iii. Click OK.
iv. New item will be created in the SharePoint External List.
Update in the Oracle DB:
I. Go to Oracle รข€“ OraClient10g home => Application Management => SQL Plus.
ii. Enter the User Name, Password and Host String as shown below.
iii. Select the table to see the changes as shown below.
iv. A new item has been added to the HR.CUSTOMERS table.
Summary:
Thus an external content type is created for oracle database using BCS Meta Man and an external list is created based on that external content type to display the Oracle data.
Monday, 7 May 2012
Reusable Workflows in SharePoint 2010
http://sharepointyankee.com/2010/12/11/options-for-deploying-reusable-workflows-in-sharepoint-2010/
Thursday, 3 May 2012
Using SPQuery to get data form SharePoint List
SPQuery: This object allows you to construct Queries to return specific items in a List.
Following sample code snippets reads a SharePoint list named "Members" and filters all the approved members using CAML query:
| using System.Collections.Generic; |
using System.Web; |
| using System.Web.UI; |
| using System.Web.UI.WebControls; |
| using Microsoft.SharePoint; |
| namespace WebApplication1 |
| { |
public partial class _Default : System.Web.UI.Page |
| { |
protected void Page_Load( object sender, EventArgs e) |
| { |
| SPList mylist= new SPSite ( "http://sharepointsite" ).OpenWeb ().Lists [ "Members" ]; |
| SPQuery query= new SPQuery (); |
| query.Query = "<Where><Eq><FieldRef
Name='Status' /><Value
Type='Text'>Approved</Value></Eq></Where>" ; |
| SPListItemCollection items=mylist.GetItems (query); |
| foreach (SPListItem membitem in items ) |
| { |
| Response.Write(membitem[ "Name" ].ToString ()); |
| Response.Write(membitem[ "City" ]); |
| } |
| } |
| } |
| } |
Monday, 30 April 2012
Wednesday, 25 April 2012
Setting up FBA Claims in SharePoint 2010 with Active Directory Membership Provider
his is a walk-through on setting up FBA Claims in SharePoint 2010
using the Active Directory Membership Provider.
The very first
step is to create a web application AND create that with claims
authentication mode. I am going to provision a web application with
claims auth mode enabled at a URL http://moss.claims.contoso.com.
Another important section
in this “Create New Web Application” screen is the “Identity Providers”
section. Once we select the authentication mode to be claims, Windows
Authentication is also plugged in as one of the provider. Check the
“Enable Windows Authentication” check box if you’d like Windows
Authentication ALSO enabled for this web application.
We can
also choose to enable ASP.NET Membership and Role Provider here. In
this case, we’ll need to provide the corresponding provider names in the
text boxes. The web.config file entries can be added later.
Those are the important
parts. You can choose the other values as you’d normally would and
create the new web application.
Once the web application is
created, we’ll first configure this web application for claims
authentication using Active Directory Membership Provider and then
create a site collection.
There are 3 web.config files we need
to edit for enabling claims:
- The config file of the Central Administration site.
- The config file of the Web Application.
- The config file of the STS (SecurityTokenService) Application. This is important because it is this service that will ensure claims tokens are being passed correctly between the provider (in our case AD) and the consumer (CA and our Web Application). Further, we can have multiple providers plugged in. STS Application manages all of these interaction for us.
Central Administration web.config changes
Open
the web.config file of your SharePoint 2010 Central Administration site
and add the following entries (NOTE: The value you need to change
according to your environment are presented in red).
First the connection string:
<connectionStrings>
<add name="adconn"
connectionString="LDAP://anomaly.com/DC=anomaly,DC=com" />
</connectionStrings>
<add name="adconn"
connectionString="LDAP://anomaly.com/DC=anomaly,DC=com" />
</connectionStrings>
And then the provider:
<membership
defaultProvider="admembers">
<providers>
<add name="admembers"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="adconn"
enableSearchMethods="true"
attributeMapUsername="sAMAccountName" />
</providers>
</membership>
<providers>
<add name="admembers"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="adconn"
enableSearchMethods="true"
attributeMapUsername="sAMAccountName" />
</providers>
</membership>
NOTE: The
connection string element should be present outside of the
<system.web></system.web> section and the provider element
should be present within <system.web></system.web> section
of the web.config file.
After this change, the web.config file
of the Central Administration site should look like what’s shown in
Image3.
Web
Application web.config changes
Open the web.config file
of the newly created web application and add the following entries
First the connection string:
<connectionStrings>
<add name="adconn" connectionString=LDAP://anomaly.com/DC=anomaly,DC=com />
</connectionStrings>
<add name="adconn" connectionString=LDAP://anomaly.com/DC=anomaly,DC=com />
</connectionStrings>
NOTE: This
entry should be made outside of <system.web></system.web>
section in the web application’s web.config file. Just like the one for
Central Administration site.
And then the provider:
<membership
defaultProvider="admembers">
<providers>
<add name="admembers"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="adconn"
enableSearchMethods="true"
attributeMapUsername="sAMAccountName" />
</providers>
</membership>
<providers>
<add name="admembers"
type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
connectionStringName="adconn"
enableSearchMethods="true"
attributeMapUsername="sAMAccountName" />
</providers>
</membership>
NOTE: This
one is a bit different. In the web application’s web.config file
search for “<membership” (without “”).
You will find there’s
already a membership and role provider plugged in (shown in Image4).
SPClaimsAuthMembershipProvider & SPClaimsAuthRoleProvider in
Microsoft.SharePoint.Administration. Claims implements the default
claims provider and Windows authentication type is plugged in through
HTTPModule (shown in Image5).
Now, we will plug in our
Active Directory membership provider to this by adding our provider
entry shown above to the <providers> element (shown in Image4).
The result should look like Image6.
Save and close this
web.config file.
STS Application web.config
changes
The next thing to do is to get your provider
entry in the STS application’s web.config file. Open Internet
Information Services (IIS) Manager on your SharePoint 2010 box. And
find the STS application (shown in Image7).
Right-click > Explore
to open the files within this application in explorer.
You
should now be in this path: C:\Program Files\Common Files\Microsoft
Shared\Web Server Extensions\14\WebServices\SecurityToken. And you will
find a web.config file in there. That’s the Security Token Service
Application’s web.config you need to add your provider and connection
information to.
Open this web.config file. If this is the first
time you are configuring claims, you’ll not find
<system.web></system.web> section in it. That’s not a
problem, just add that section yourself. What works out for me, is to
go to the end of this web.config file and do the following:
First
add the connection information just before </configuration>. And
then after the <connectionStrings></connectionStrings>
section, add a <system.web></system.web> section and add our
provider information into it. The result should look like Image8.
After this doing an
IISRESET might be a good idea.
You are good now with regards to
web.config file entries. Now you have to get some configuration done
through UI to wire-up our provider to the web application. First, go to
the Web Applications Management page in Central Administration site,
click the web application you want to enable FBA claims on and choose
Authentication Providers from the ribbon. From the Authentication
Providers dialog, choose Default. Scroll a bit down to find Identity
Providers section. Check Enable ASP.NET Membership and Role Provider
(NOTE: You can also do this at the time of creating this web
application) and type in the name of your provider. In my case, it is
admembers. After you do this, UI should like Image9. Hit Save.
Close
the Authentication Providers Dialog UI.
Now, hit User Policy
ribbon option in the Web Applications Management page having selected
your web application. Hit Add Users in the Policy for Web Application
dialog. Hit Next in Add Users dialog. Use the Browse button in the
Choose Users people picker control. Notice the Select People and Groups
dialog that comes up is changed. Noticeable difference is that there
are sections like Active Directory, All Users, Forms Auth &
Organizations. Type in an active directory user alias and search.
There should be 2 results for the same user. One identified through
NTLM authentication and the other through FBA Claims authentication
that’s using Active Directory membership provider (refer Image10).
Select the user from
Forms Auth result. In my case, it’s the first user displayed in
Image10. Hit Add and then OK in the Select People and Groups dialog.
In the Add Users dialog, check Full Control - Has full control for the
Choose Permissions section and hit Finish. NOTE: If you want to
provide full control to other users either from FBA Claims
authentication or NTLM authentication, you can do that here.
Now,
your Policy for Web Application dialog should look like Image11. Hit
OK.
Now, you can create your
top-level site collection in this web application. Click Application
Management from the left navigation in Central Administration site.
Click Create Site Collections. Ensure that your web application plugged
in with FBA Claims is selected in the Web Applications drop-down.
Provide a title, description and pick up a template of your choice. In
the Primary Site Collection Administrator section, type in the alias of
the site collection administrator. This should be the NTLM
authenticated user. The entries should look like Image12. Hit OK to
create the site collection.
Once the site
collection is created, browse to it. A page as shown in Image13 will be
displayed.
Choose Windows
Authentication from the drop-down and you’ll log into the newly created
site collection using Windows Authentication. Now, you need to add
another site collection administrator. But this must be from the active
directory membership provider. You can login through forms
authentication using the user you added with full control in user policy
settings above. If you choose to not do that (which most customers
do), you can do one of the following steps to add another site
collection administrator to this FBA Claims Authentication enabled site.
- Go to Central Administration site > Application Management from left navigation > Change site collection administrators > add the alias of the user from FBA Claims Authentication as the secondary site collection administrator and click the Check Names button to resolve it.
- Login to the Claims Authentication enabled site using Windows Authentication. Site Actions > Site Settings > Site collection administrators > type the alias of the user from FBA Claims Authentication in the Site Collection Administrators and click the Check Names button to resolve it. This is shown in Image 14.
After this, you should
be able to login to this site using the same URL with both Windows and
Forms Authentication (Forms Authentication login shown in Image15)
WARNING: Take utmost care when making the web.config file
entries because that’s where thing go wrong. And if it does,
identifying and fixing it might be a herculean task – trust me :)Where is SharePoint web.config
There is a separate web.config file for each Web Application / IIS
Website which is running an instance of SharePoint. For example, if
Sharepoint, Central Admin and the MySite host are all running as
separate Web applications (different Application pools) on separate IIS
sites, there will be a web.config file in the root of the virtual
directory for each application. There is also a separate web.config file
which contains configuration details for the “_layouts”, “_catalogs”,
etc directories of SharePoint sites.
You should not make changes to the web.config file in a production
environment, or while in production. Back up your entire SharePoint
environment, including all databases prior to commencing any major
troubleshooting or configuration changes. You should attempt and test
any modifications to the web.config file in a non-production environment
which is configured the same as the live environment. Once you are
confident the the changes apply the necessary changes if required to the
live environment while it is not in use. The IIS Website will
automatically reset when the web.config file is saved so changes will be
applied immediately. Be sure that you have not left syntax or any other
errors in the file before saving changes.
The web.config files are genearally found in the following
locations:
- web.config file in the root folder of each virtual server / IIS Application.
Local_Drive:\Inetpub\wwwroot
This is the usually the file that contains most of the web
configuration of a SharePoint site collection. To display full errors
you would need to modify this web.config file. There may be one for each
of the SharePoint applications running in some cases (MySites, Multiple
Portals or Instances of SharePoint, Central Admin, etc.). If this is
the case, you will only need to modify the web.config file which is in
the root of the virtual directory for the instance of SharePoint which
you using. To find out which directory is used by various SharePoint
applications/websites, view the properties of the SharePoint website in
IIS and from the “Home Directory” tab, the value in the “Local path”
field will take you to the directory where the web.config file is for
the specific instance of SharePoint / Application in IIS.- web.config file used in Web Part resources for the Global Assembly Cache (GAC)
Local_Drive:\Program Files\Common Files\Microsoft Shared\Web
Server Extensions\wpresources
- web.config configuration file(s) for extending other virtual servers
Local_Drive:\Program Files\Common Files\Microsoft
Shared\Web Server Extensions\60\CONFIG
- web.config file which defines configuration settings for the /_vti_bin virtual directory
Local_Drive:\Program Files\Common Files\Microsoft
Shared\Web Server Extensions\60\ISAPI
- web.config file which defines configuration settings for the /_layouts virtual directory
Local_Drive:\Program Files\Common Files\Microsoft
Shared\Web Server Extensions\60\TEMPLATE\LAYOUTS
- web.config configuration file for Central Administration pages.
Local_Drive:\Program Files\Common Files\Microsoft
Shared\Web Server Extensions\60\TEMPLATE\ADMIN\Locale_ID
Tuesday, 24 April 2012
Beautiful point on document library in SharePoint 2010
Here we will see what will happen when we create a list
or a document library inside a site. You may create a list using the browser or you
may create a list using SharePoint 2010 server object model.
Here it is:
Whenever
you will create a document library SharePoint creates a folder with
same name as the document
library at the root of the web site.
Then
it creates another folder with name Forms. And SharePoint creates a set
of site pages like DispForm.aspx,
EditForm.aspx, AllItems.aspx, and Upload.aspx inside the Forms folder.
This pages are required to add
and manage content for that document library.
This site pages
can be accessible using SharePoint object model using the SPFile class
like below:
SPWeb site = SPContext.Current.Web;
SPFile sitepageAllItems = site.GetFile("[Document Library
Folder Name]/Forms/AllItems.aspx");
SPFile class has
different methods like Delete, MoveTo, CopyTo methods to work with site
pages. Suppose by using
Delete method you can delete the site page from the site.
Application Pages in SharePoint 2010
Application pages in SharePoint 2010 is a very useful
concepts.
-These pages will be available to all sites of a farm.
-They are
deployed under C:\Program Files\Common Files\Microsoft Shared\Web Server
Extensions\14\TEMPLATE\LAYOUTS folder.
-They are
available through a virtual directory namely _layout.
-These pages
are basically for administrative tasks.
-To create an
application page using Visual Studio 2010 is very easy. By using the
template Application Page you can create an application page.
-By default the
page will use the default.master page.
-The page is
derived from the base class LayoutsPageBase which is derived from
Microsoft.SharePoint.WebControls namespace.
-Application
pages cannot be personalized or customized by the end user because they
are defined on the file system.
-Example of application page is settings.aspx.
Save site as template is not appearing for publishing sites
Introduction:
Here we will discuss how save site as template option is
not appearing in a publishing site but it appears for team site in
SharePoint 2010.
Description:
"Save site as template" is a very good option in
SharePoint. By using this you will create a site by using this template.
If you will go to Site Actions -> Site Settings and
in the Site Settings page under the Site Settings you will able to see
Save site as template option.
If you will open a team site and go to Site Actions
-> Site Settings. This will open the Site Settings page. In this page
under the Site Settings section you will see Save site as Template
option as shown in the figure below.
But if you will check the above step in a
publishing site then that Save site as template option will not be available. you can also check the
figure below.
I did not find the exact reason of this but to overcome the
situation Turn off the publishing feature and then try opening the Site Actions
-> Site Settings and in the Site Settings page under the Site Settings, now you will see the link "Save
site as template."
Disadvantages of external lists in BCS
-Approval of items is not supported.
-Attachments
are not supported directly.
-Check-in and checkout of items are not
supported.
-Using standard site content types in External
Lists is not supported.
-Drafts of items are not supported.
-Send-To
operations are not supported.
-List event handlers are not supported.
-Datasheet
View is not supported.
-Querying through LINQ to SharePoint is not
supported.
-Document templates are not supported.
-Versioning
of items is not supported.
-Starting workflows from items is not supported,
but workflows can read or write to External Lists through the SPList
object.
-Validation formulas are not supported.
Export Import option in SharePoint 2010
Though SharePoint 2010 provides an option for export
where SharePoint 2010 allows you to export websites and lists and also
an import option, where a user can import a site or a list.
Export:
You can use central administration,
stsadm or powershell to export a site or a list.
Stsadm:
STSADM -o export -url <url> -filename
<filename>
There are also
lots of optional parameters are available.
PowerShell:
Export-SPWeb <url> -path
<filename>
There are also
lots of optional parameters are available.
Still it has
some limitations for which we should use backup rather than export.
Limitations
of Export:
- Export is just
like copy a web site.
- But here are some characterstics that export will not
keep like Settings not preserved are workflow associations and instances, file check-out status,
alert subscriptions, tags and notes, and personal Web part settings.
- It takes long time and place a large burden on your
farm.
- Microsoft is recommending not to export more than 1 GB.
Import:
You can use stsadm or powershell to import a web site or
a list. But to import a site first the top level site should be created
with the matching site defination (like team site or blank site etc)
and also no content need to be there.
SharePoint
will create the child web sites automatically, but top level site needs
to be created before import.
If
you are importing a list, if the lists exists then it must be the same
template. If the list does not exists SharePoint will create.
Stsadm
command:
STSADM
-o import -url <url> -filename <filename>
There are also lots of optional parameters are
available.
PowerShell commad:
Import-SPWeb <url> -Path
<filename>
There are also
lots of optional parameters are available.
SharePoint 2010 object model classes
Here there are some SharePoint
Object model classes.
In the top SPFarm class is there.
SPFarm: This reference the
entire SharePoint Server Farm.
By using this you can create a
new farm or you can connect to a existing a existing farm.
Namespace:
Microsoft.SharePoint.Administration
SPServer: By using this
class you can browse through the collections of servers belongs to the
Farm.
SPSite: Represent a Site
collection.
SPWeb: Represent a web site.
SPUserToken: The
SPUserToken class represents a token for a valid SharePoint user.
SPList: SPList corresponds
to a single list instance, whether that is a list of items or a
document library.
SPListItem: This defines a reference to a specific
item of a list.
SPDocumentLibrary: This type represents a document
library.
SPFile: This class is
used to enumerate the files contained in a document library.
SPPrincipal: This class is
the parent class for SPGroup and SPUser.
SPControl: This class we
need while developing web controls or Web Parts.
SPContext: This is a very
useful class and it has some direct methods to access useful information
about current requests.
SPContext class in SharePoint 2010
- Represents the context of an HTTP request in Microsoft
SharePoint Foundation.
- This class also available in SharePoint Sandboxed
solution also.
- Present in the Assembly Microsoft.SharePoint.dll.
- This class
returns current information about list, site and also site collection,
also you can retrieve current user name also.
- Here are
some example of SPContext class
string
userLoginName=SPContext.Current.Web.CurrentUser.LoginName; //This will
return current login name.
SPList currentList = SPContext.Current.List; //Give
you the current list associated with the context
SPWeb
currentWeb = SPContext.Current.Web; //Returns the current site
associated with the context
SPSite currentSite = SPContext.Current.Site; //Returns
current site collection associated with the context
SPWebApplication currentWebApplication =
SPContext.Current.Site.WebApplication; //Returns current web application
associated with the context.
SPContext.Current.SiteFeatures
//Give you the activated site collection features of the SharePoint
context.
You can check more on msdn in this URL: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spcontext.aspx
Event receivers in sharepoint 2010
Through this article I am trying to explain about event
receivers in SharePoint.
An event receiver is a class that contains one or more
methods known as event handlers that are executed automatically by
SharePoint in response to events such as adding item to a list.
You can use event handlers for data validation, data
integrity etc.
SharePoint categories events into of two types 1. Before
events (synchronous events) 2. After events (asynchronous events).
1. Before
events (synchronous events):
These events fires before an action occurs and before
SharePoint has written any data to the content database.
For example ItemAdding event will fire when trying to
add an item to a list. These events does support cancelling of event
action. These events are always end with 'ing' like FieldAdding,
ItemAdding, ItemUpdating, WebAdding, WebDeleting etc. These events are
also know as synchronous events.
2. After events (asynchronous events):
These events
fire after the event action has completed and after SharePoint
Foundation has written to the content database to commit the event
action. These events does not support cancelling of event action. These
events does support cancelling of event action. These events are always
end with 'ed' like FieldAdded, ItemAdded, ItemUpdated, WebAdded,
WebDeleted etc. These events are also know as asynchronous events.
Events,
Event Receivers & Object Model:
Event
receivers are nothing but custom classes which are derived from event
receiver base classes that are defined by Microsoft in
Microsoft.SharePoint assembly.
Some of the base classes are
SPItemEventReceiver: There are related to SharePoint
items.
SPListEventReceiver:
Related to lists.
SPWebEventReceiver:
Related to webs.
SPWorkflowEventReceiver:
Related to workflows instances. etc.
Remember all
these classes(except SPEmailEventReceiver and SPFeatureReceiver) are
derived from a common base class know as SPEventReceiverBase.
Here there
are different event receivers:
Item-Level
Event Receivers:
The base class for this type of event receivers are
SPItemEventReceiver and are related to SPListItem instances.
Some events
are: ItemAdded, ItemAdding, ItemCheckedIn, ItemCheckingIn,
ItemCheckedOut, ItemCheckingOut, ItemDeleted, ItemDeleting etc.
List-Level
Event Receivers:
The base class for this type of event receivers are
SPListEventReceiver and events are related to lists. These events fires
whenever any changes to the fields of an existing list as well as adding
or deleting list instances.
Some events are: FieldAdded, FieldAdding, FieldDeleted,
FieldDeleting, FieldUpdated, FieldUpdating, ListAdded, ListAdding,
ListDeleted, ListDeleting etc.
Web-Level Event Receivers:
These
are events related to Site Collection deletion and website creation,
deletion, moving, and provisioning. The base class for these type of
event receiver is SPWebEventReceiver.
Some events
are: SiteDeleted, SiteDeleting, WebAdding, WebDeleted, WebDeleting,
WebProvisioned etc.
Workflow Event Receivers:
These
event receivers are for running workflows and the base class for these
type of event receivers are: SPWorkflowEventReceiver.
Some events
are: WorkflowStarting, WorkflowStarted, WorkflowCompleted etc.
E-Mail
Event Receivers:
These event receivers are for e-mail–enabled list
instances and the base class is SPEmailEventReceiver.
For this type of event receivers you have to override
the EmailReceived method.
Tuesday, 17 April 2012
SharePoint 2010: Add Colors, Borders and Fonts to Web Parts
6/04/2011
SharePoint 2010: Add Colors, Borders and Fonts to Web Parts
In October of last year I wrote an article on changing the color, borders and fonts for SharePoint 2007 web parts. Here (finally) I will do the same for SharePoint 2010 web parts. The previous article used JavaScript to make these changes while this one will use CSS.A 2007 version of this article is here.
Do you want to change all web parts in all pages, all web parts in a single page or just one web part? Each of these will require a slightly different approach.
- All web parts in all pages?
Add the CSS to the master page, either inline or linked to a file - All web parts in a single page?
Add the CSS to the page using SharePoint Designer or a Content Editor Web Part
(If using a CEWP, add the web part below the web parts to change, i.e. last zone, last web part) - Just one web part?
Add the CSS as for a single page, but prefix all of the CSS entries with the ID of the web part to change
To use the sample CSS below for all web parts, remove all of the “#MSOZoneCell_WebPartWPQ5” references.
A Web Part
Here is a terribly abused web part :-) that has an exaggerated set of colors and fonts to make each areastand out.
The CSS
Notes:- You don’t need to use all of the CSS. Pick and choose as needed.
- This is not a complete list of what you can change in a web part. Search the HTML source of your web part page for ideas, or do a web search to see what others are doing.
- “#MSOZoneCell_WebPartWPQ5” is the ID of a single web part to change. This is only need when changing a single web part on a single page. Your web part will have a similar ID, but with a different number.
- The number in the web part ID may change if the web part is moved on the page.
- “#MSOZoneCell_WebPartWPQ5.ms…” vs “#MSOZoneCell_WebPartWPQ5<space>.ms…”
The space is used to indicate a parent-child relationship. With the space, CSS looks for an element with an ID of “#MSOZoneCell_WebPartWPQ5” and then looks for a child element with a class name of “ms…”. Without the space, CSS looks for single element that has both the ID and the class name. - Anywhere there is a background property you can also set a background image by using:
background-image:url(' someimagepath '); - Colors can be set using color names (“green”) and color numbers (“#00FF00”)
- The .ms-wpTdSpace class name is used to identify the corners or ends of the web part’s title area. If you don’t define anything for these they stay hidden. See the links at the end of this article for ideas for taking advantage of these corner areas. (How about rounded tab-like corners!)
- <style type="text/css">
/* === Title bar CSS === */
/* TR - title bar for web part */
#MSOZoneCell_WebPartWPQ5 .ms-WPHeader
{
background-color:green;
}
/* H3 - Text in title bar of web part */
#MSOZoneCell_WebPartWPQ5 .ms-WPTitle a
{
color:white;
font-family:"Comic Sans MS";
font-size:24pt;
}
/* TD - far left and far right (corner) cells of title bar - useful for round corner tricks */
#MSOZoneCell_WebPartWPQ5 .ms-wpTdSpace
{
/* background-image:url(' someimagepath '); */
width:30px !important;
background-color:red;
}
/* web part check box */
#MSOZoneCell_WebPartWPQ5 .ms-WPHeaderCbxHidden
{
display:none;
}
/* === Web part background CSS === */
/* TD - background for all but title bar of web part */
#MSOZoneCell_WebPartWPQ5.s4-wpcell
{
background-color:lightgreen;
/* border-style:dashed; */
border-style:dashed;
border-width:5px;
}
/* TD - paging area (i.e. 1 - 5) */ #MSOZoneCell_WebPartWPQ5 .ms-bottompaging td{ background-color:yellow !important;} /* hide the gray line above "add new" link */
#MSOZoneCell_WebPartWPQ5 .ms-partline
{
display:none;
}
/* selected (clicked) web part background */ #MSOZoneCell_WebPartWPQ5.s4-wpActive{ background-color:fuchsia; border-color:red; /* border-style:dotted; */
}
/* === Column headings === */
/* color for sortable column headings */
#MSOZoneCell_WebPartWPQ5 .ms-vh-div a
{
color:red !important;
}
/* color for non-sortable column headings */
#MSOZoneCell_WebPartWPQ5 .ms-vh-div
{
color:red !important;
}
/* === List text CSS === */
/* item description text */
#MSOZoneCell_WebPartWPQ5 .ms-vb2,
#MSOZoneCell_WebPartWPQ5 .ms-vb-user a,
#MSOZoneCell_WebPartWPQ5 .ms-vb-title a
{
color:yellow !important;
font-size:12pt;
}
/* TR - alternating (#2,#4,#6...) row of web part */
#MSOZoneCell_WebPartWPQ5 .ms-alternating
{
background-color:navy;
Subscribe to:
Posts (Atom)