Dec 15, 2009

Create a sharpoint webpart in Visual Studio 2010

Creating a web part becomes much easier with Visual Studio 2010 (beta 2). The structure is a dummy web part which simple load a user control:;

In theory, a control can be added through

  • dynamically in CreateChildControls() of web part file

  • declarative in ascx file of user control

  • dynamically in Page_load() of user control's code behind

adding a custom property is very easy now, all need to do is add the following 2 attributes to any property: [WebBrowsable(true), Personalizable(true) ]

in .webpart, you can add default velues just as any other OOB properties

As custom properties are open to injection of user script (good or bad), SharePoint 2010 introduce 2 new flags to enforce security at both webpart level and property level:

SafeAgainstScript attribute in

[RequiresDesignerPermission] attribute for web part's property

see here for more details

Dec 11, 2009

Create a custom SharePoint application page and use ECMAScript ClientOM

You can create a full-blown Application Page with a dll by using VS 2010, see this blog for details. Or you can follow the simple steps to create it without VStudio:

* copy from any application page from layouts/

* delete all contents in <asp:Content id="PlaceHolderMain" >

*change the page inheritance to: Microsoft.SharePoint.WebControls.LayoutsPageBase

*Find the buttons template section:


<asp:Button UseSubmitBehavior="false" runat="server"

class="ms-ButtonHeightWidth" OnClick="BtnUpdateWeb_Click"

Text="<%$Resources:wss,multipages_okbutton_text%>" id="BtnCreate"



* Define OnClick function.
<script runat="server">

protected void BtnUpdateWeb_Click(object sender, EventArgs e) { ...}

</script >

*Note: The above template also defines both "OK" and "Cancel" buttons on the page.

by now, it should be a functioning application page, and you can load ClientOM by adding the follwoing in any asp:content:

<SharePoint:ScriptLink runat="server" Name="sp.js" OnDemand="true" Localizable="false" />

Then you can use ClientOM in any javascrip such as:

function retrieveWebSite() {

var clientContext = new SP.ClientContext.get_current();

this.oWebsite = clientContext.get_web();

clientContext.load(this.oWebsite); //this is to make oWebSite available in client




Dec 3, 2009

SharePoint Content Deployment

Recently I have deployed sharepoint content from 32 bit window 2003 to 64 bit window 2008, here are some pitfall I ran into:

  • Target SharePoint server has to be configred to accept "incoming content deployment jobs" and check "Do not require encryption" if SharePoint Central Admin site is not using SSL;
  • Target SharePont site collection has to use blank template;
  • Deploymentmanifest.xsd (under 12 hives\Template\xml on Target SharePoint Server) has to add the followings (this only requires for 32 to 64 bit mix)

<xs:attribute name="AllowAutomaticASPXPageIndexing" type="xs:boolean" use="optional" >
<xs:attribute name="ASPXPageIndexMode" type="xs:string" use="optional" > < xs:attribute name="NoCrawl" type="xs:boolean" use="optional" >
< xs:attribute name="CacheAllSchema" type="xs:boolean" use="optional" >