C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » Sharepoint »

what is object model in sharepoint2007?


Posted Date: 20 Jan 2009      Posted By: lakshmi      Member Level: Gold     Points: 1   Responses: 4



please tell me what is object model in share point2007?.




Responses

Author: Aslam     20 Jan 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 6

Hi Lakshmi

Sharepoint object model is heart of sharepoint programming

Microsoft has spent a significant amount of time developing .NET namespaces for SharePoint.
This comprehensive set of namespaces allows you programmatic access to a significant portion
of WSS and MOSS. The SharePoint Services object model is extensive, to say the least.
There are 30 namespaces within the object model and dozens of classes covering most of the
features of SharePoint. The depth and breadth of the architecture makes it impractical to
study the object model directly. Instead, it is better to use the object model to address broad
categories of solutions that you can create.


Accessing objects in the SharePoint model is accomplished in a manner similar to any hierarchical
object model you may have worked with in the past. The key to navigating such a model
is to find the starting point for the model. In SharePoint, this is done through the ASP.NET
Context object using the following code:
SPSite site = SPControl.GetContextSite(Context);
The SPControl class is a member of the Microsoft.SharePoint.WebControls namespace
and is the base class from which all other WebControls in the namespace are created. You
do not have to create an instance of the SPControl class to use it. Simply call the
GetContextSite method and pass the Context property. The Context property comes from
the System.Web.UI.Page object and is always available to web parts and ASPX pages that
reside in the LAYOUTS directory. The GetContextSite method returns an SPSite object,
which represents the site collection where the web part or ASPX page is currently running.
SPSite objects contain information about the site collection and the sites within it. In
order to access any particular site in the collection, you must return a collection of SPWeb
objects. You may then access the individual web sites by enumerating them or accessing
one directly through an index.

Accessing Lists and List Items
Along with site collections, you will access lists and list items frequently. Typically when dealing
with lists, you are interested in a particular site rather than a site collection. You can get
a reference to an individual site by using the GetContextWeb method of the SPControl object.
Once a site is open, you may access all of the lists it contains through the SPListCollection
object. The collection contains an SPList object for every list on the web site. The following
code shows how to enumerate the lists for the current web site

SPWeb site = SPControl.GetContextWeb(Context);
SPListCollection lists= site.Lists;
foreach(SPList list in lists)
{
//add code here
}
It is important to understand that SharePoint considers almost everything to be a list. This
includes not only obvious components such as task lists, but more subtle components such as
document libraries and discussion forums. Therefore, you will find it useful to be able to differentiate
between various lists that are returned in code. Each SPList object has a BaseType
property that returns an SPBaseType enumeration specifying what kind of list is represented.
Here is a list of the members of the SPBaseType enumeration:
• SPBaseType.DiscussionBoard
• SPBaseType.DocumentLibrary
• SPBaseType.GenericList
• SPBaseType.Issue
• SPBaseType.Survey
• SPBaseType.UnspecifiedBaseType
Once you have accessed a list of interest, you may subsequently access the items in
the list. Each item in the list is represented by an SPListItem object contained in an
SPListItemCollection object. Enumerating these list items follows the same pattern as
you have already seen.
Regardless of whether you are accessing sites, lists, or items, each object has a set of
properties and methods that are meaningful. Typically, this means returning the Name, Title,
or URL associated with an object. Additionally, each object has some special properties and
methods designed to return useful collections. For example, you can return just the webs
associated with the current user by utilizing the GetSubwebsForCurrentUser method of the
SPWeb class


for further information please read sharepoint SDK which is freely downloadable.

I hope you got some idea now.



Author: Santhi    22 Jan 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 3

Hi,

The object model can be used when the application will run on the server where SharePoint is installed or in assemblies that are run with in a site. As an alternative to programming against the SharePoint web services you can use the SharePoint object model.
In Sharepoint Object there are two Important namespaces.
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.



Author: rashmi tiwari    28 Jan 2009Member Level: SilverRating: 2 out of 52 out of 5     Points: 6

About the object model in sharepoint2007.. :)


1. If you want a list to show up in the left side of Sharepoint site, use OnQuickLunch property, set the property to true, then update ... a few times ...

2. When adding the fields to the list, if you want to add them to the DefaultView do not add them directly to the DefaultView object, like in list.DefaultView.ViewFields.Add .... Rather iterate through the collection of views of the list, get the one that is default and add to that object's viewFields collection.

3. Do NOT modify properties of spList through indexer of collection, there is a bug which makes the modifications not to be saved. Rather have an object take the value and modify the object.
Ex: USE
spList = web.Lists[guid];
spList.OnQuickLaunch=true;
INSTEAD of
web.Lists[guid].OnQuickLaunch=true;


4. You can not add a custom field (that does not have a base type) to a collection , for example Resizable Image, the only way you can add it is with
FieldCollection.AddFieldAsXmlSchema

5. The only way you can put an user other than the ones in web.AllUsers in a SPFieldUserValue is
SPUser newUser = web.EnsureUser(@"domain\username");
web.AllowUnsafeUpdates = true;
SPFieldUserValue userValue = new SPFieldUserValue (web, newUser.Id, newUser.LoginId);

EnsureUser is a rather interesting method. You will see more about this on my blog or I'll put a link to a blog that explaines it ...

6. There is no property for a column to provide context menu edit link. The column with edit link can be extended as a custom column or easier, the default Title column can have its display name changed to title you want to have on the column with link menu.

7. SPFieldDateTime's property Date Only and default value property set to Today in UI web , can be programatically set like this:

SPFieldDateTime field = (SPFieldDateTime)list.Fields[columnName];
field.DisplayFormat = SPDateTimeFieldFormatType.DateOnly;
field.DefaultValue = "[today]";

8.When adding a workflow programatically to a list perform the next steps:

//SPListHelper.GetList is a helper function that iterates through site lists for the wanted list.
//name - The name of the workflow association (cob in our case)
const string TASKS = "Tasks";
const string WORKFLOWHISTORY = "Workflow History";
string COMPANYONBOARDING = "Company On Boarding";
SPWorkflowTemplate baseTemplate = site.WorkflowTemplates[COMPANYONBOARDING];
SPList tasks = SPListHelper.GetList(site, TASKS);
if (tasks == null)
{
site.Lists.Add(TASKS,TASKS, SPListTemplateType.Tasks);
tasks = site.Lists[TASKS];
}
SPList wfHistory = SPListHelper.GetList(site, WORKFLOWHISTORY);
if (wfHistory == null)
{
site.Lists.Add(WORKFLOWHISTORY, WORKFLOWHISTORY, SPListTemplateType.WorkflowHistory);
wfHistory = site.Lists[WORKFLOWHISTORY];
}
SPWorkflowAssociation newAssociation =
SPWorkflowAssociation.CreateListAssociation(baseTemplate, name, tasks,wfHistory);
newAssociation.AutoStartCreate = true;
list.AddWorkflowAssociation(newAssociation );
list.Update();

SPListHelper.AddColumnToDefaultView(list, name);

9. Person Or Group column appears in Sharepoint Object Model as SPFieldUser. A Person Or Group with Multiple selection and Show Field = Account, is programatically set as it follows:



Author: LOGESHWARAN    10 Feb 2009Member Level: GoldRating: 2 out of 52 out of 5     Points: 6

As an alternative to programming against the SharePoint web services you can use the SharePoint object model. The object model can be used when the application will run on the server where SharePoint is installed (such as a console or WinForm application) or in assemblies that are run within a site (such as a Web Part).

First, you will need to create a reference to “SharePoint.dll” assembly in your Visual Studio 2005 project. This is located at:

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\ISAPI\Microsoft.SharePoint.dll

A recursive function nicely solves the problem of loading the site hierachy into a tree view control. The method below is passed the tree node into which the site list will be loaded, and a SPWeb object representing the site whose sub-sites will be loaded:

private void FillSubWeb(TreeNode tn, SPWeb webSite)

{

foreach (SPWeb theWeb in webSite.Webs)

{

TreeNode subTN = new TreeNode(theWeb.Name);

tn.Nodes.Add(subTN);

FillSubWeb(subTN, theWeb);

}

}

This method iterates over the “Webs” collection which returns each sub-site. A new TreeNode object is created with the site name. The node is added to the tree view control. Lastly, the FillSubWeb method is called recursively, passing the TreeNode and theWeb object to load the sub-sites for the current site.

The following code kicks off the loading of the sites:



SPSite site = new SPSite

(“http://moss2007:8100/sites/intranet”);

SPWeb rootWeb = site.AllWebs[0];



TreeNode tn = new TreeNode

(“http://moss2007:8100/sites/intranet”);

tvSites.Nodes.Add(tn);

FillSubWeb(tn, rootWeb);

The code gets a reference to the site collection from the URL, and then obtains a reference to the top-level web (site) for the site collection. A tree node is created and added to the tree view control to represent the site collection, and then the FillSubWeb method is called to start the recursive process.

REGARDS
LOGESHWARAN.P
mailto: logesh_ajax@logeshwaran.co.cc



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Read file content from document library and write to a textbox.
Previous : defenition
Return to Discussion Forum
Post New Message
Category: Sharepoint

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use