Monday, March 30, 2009

SharePoint Object Model

The SharePoint object model has four top-level objects:

* SPWeb (represents an individual site).
* SPSite (represents a site collection, which is a set of web sites).
* SPVirtualServer (represents a virtual server).
* SPGlobalAdmin (used for global administration settings).

In order to perform actions on data within a web, it is necessary to first get an SPWeb object (e.g. SPWeb MyWeb = SPControl.GetContextWeb(Context);)

The complete object model is grouped into lists, files (documents), security and administration:

* Lists - use these objects under the Microsoft.SharePoint namespace to view and edit data in SharePoint lists:
o SPList (basic list object for getting to list data).
o SPListCollection (collection of list objects).
o SPListItem (item/row in a list).
o SPListItemCollection (collection of list items).
o SPView (view of a SharePoint list).
o SPField (field/column in a list).
o SPListTemplate (template for a list).
* Files - use these objects under the Microsoft.SharePoint namespace to access document files in SharePoint sites:
o SPFile (file object).
o SPFileCollection (collection of files).
o SPFileVersion (version of a file).
o SPFolder (folder object).
o SPDocumentLibrary (document library object).
o SPDocDiscussion (discussions on a file).
o SPDocTemplate (used when creating a new file).
* Security - use these objects under the Microsoft.SharePoint namespace to edit access rights and security information:
o SPUser (user object).
o SPRole (site group object).
o SPGroup (cross-site group object).
o SPPermission (assigned permissions).
o SPRightsEnumeration (available permissions).
* Administration - use these objects under the Microsoft.SharePoint.Administration namespace to edit server-wide administrative settings.
o SPGlobalAdmin (top level administration object).
o SPVirtualServer (virtual Server object).
o SPQuota (storage/user quota limit object).
o SPGlobalConfig (configuration options).
o SPSiteCollection (collection of sites on a virtual server).

In terms of mapping the user interface onto the object model terminology:

* Site Collection = site.
* Site = web.
* Top-level site = rootweb.
* Subsite = subweb.

Friday, March 13, 2009

SharePoint Escape Characters

Ran into a problem when I was writing script to add a new entry to a column (using XML web services). I could not get the column names the same as the were name. Like my "e-mail" column. So for that one I had to type for the id in the script e_x002d_mail.

Blank space: _x0020_
Underscore: _x002d_
Dash: _x0027_

Here is the Format:

_x00[the escape code]_


Char Code

[space] 20
< 3C
> 3E
# 23
% 25
{ 7B
} 7D
| 7C
\ 5C
^ 5E
~ 7E
[ 5B
] 5D
` 60
; 3B
/ 2F
? 3F
: 3A
@ 40
= 3D
& 26
$ 24

SharePoint Lists Filter Keywords and Expressions In Views

[Today] The current date.

[Me] Current User of the site.

[Modified] Date item was last modified.

Filter Expression Examples:

[Modified]+7 A week after the last modification.

DATE(YEAR(Modified),MONTH(Modified),DAY(Modified)+5) 5 Days after the last modification.


Formulas and Functions:

http://office.microsoft.com/en-us/sharepointtechnology/CH100650061033.aspx

Thursday, March 5, 2009

How to add sharepoint DateTime Control and People Picker in custom application page

People Picker :
The control is actually called a "
PeopleEditor" and is in the 'Microsoft.SharePoint.WebControls' namespace. You will need to add a reference to 'Microsoft.Sharepoint.dll' to your project in Visual Studio, which is something you probably already have if you are writing anything that works with SharePoint.

First, we need to add a reference to the Namespace containing our control:

<%@ Register Tagprefix="wssawc" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" / %>

Next, add the PeopleEditor control to your page:

<wssawc:PeopleEditor
AllowEmpty="false"
ValidatorEnabled="true"
id="userPicker"
runat="server"
ShowCreateButtonInActiveDirectoryAccountCreationMode="true"
SelectionSet="User" /
%>

Next, add an object on the server to work with the control:

using Microsoft.SharePoint.WebControls; //add a reference to Microsoft.SharePoint.dll if needed

public class MyPageName : Page
{
protected PeopleEditor userPicker;

}
Now, add your code needed to retrieve the entities:

public void btnSave_Click(object sender, System.EventArgs e)
{
….
PickerEntity pe = (PickerEntity)userPicker.Entities[0]; //gets first user in list
string username = pe.Description;

SPUser user=web.AllUser[username];

}

Notes:
The Description property will return the full account name (e.g. domain\username)
The DisplayText property will return the resolved name in the editor control (e.g. First Last)


Date Time Control :


You can create user control webpart for that and add this webpart to sharepoint environment othrewise you can get error like " object reference can not set".

Cheers it and enjoy.

Google Search Webpart in sharepoint


Below is a cheap way to get a Google search on your site:
1. Navigate to C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\TEMPLATE\LAYOUTS

2. Create a new folder called "external"

3. Inside the folder create a single HTML page with the following contents:

<FORM method=GET action="http://www.google.com/search"
target="_blank">
<A HREF="http://www.google.com/" target="_blank">
<IMG SRC="http://www.google.com/logos/Logo_40wht.gif" border="0"
align="absmiddle"></A>
<INPUT TYPE=text name=q size=30 maxlength=255 value="">
<INPUT type=submit name=btnG VALUE="Google Search" style="font-
size:10">
</FORM>


4. Save the file as "googlesearch.htm"

5. Next drop a Page Viewer Web Part onto your page and point it to the page you created. The url to the page will be http://tushar/_layouts/external/google.htm

Cheers it and enjoy it.