Feb 26, 2010

ScriptManager & Scripts from CDN such as AJAX Library

With roll out of ASP .Net AJAX Library, adding ajax capabilities in scripts is nothing but a link to CDN:

<script src="http://ajax.microsoft.com/ajax/beta/0911/Start.debug.js" type="text/javascript" > </script >

It will load all scripts needed for ajax development regardless of .Net Framework. However if asp:ScriptManager is also used, it will load script from framework. That will cause some visioning problems, and it is the case for sharepoint pages(this seemingly only happens if usng dataview control). SharePoint 2010 master page has ScriptManager embedded and is used by both site pages and application pages . As currently in beta, the workaround is to locally include MicrosoftAjax.js (see here for details).

Another cool thing about ScriptManage or ScripManagerProxy is its asp:serviceReference, it will inject a proxy script class on fly to allow client script to call backend ajax enabled WCF service.

Feb 16, 2010

Modify SharePoint Solution Package (WSP) without rebuilding

Recently a SharePoint group memeber asked how to modify a text file inside a wsp without knowing source files's folder structure (i.e, it can't simply rebuilt by wspbuilder). Initially i thought it can be done just by unzip and zip again wsp file. It turns out even though wsp can be extracted by winzip, it can't be zipped back (the resulting wsp can't be added).

The right and simple way to do this is to use winzip extract and then use Cab SDK (download here) command such as:
cabarc -r -p -P winzip n bcs.wsp winzip\*.*

This works for both MOSS 2007 and SharePoint 2010 farm solution, but it doesn't work for SharePoint 2010 sandbox solution. I will update when I find a way to do it for sandbox solution as well (wait for 2010 RTM)

Feb 14, 2010

SharePoint BCS Entity Names Mapping

The high level of BCS structure consisits of one Entity Service, which is exposed public as External Content type wth CRUD methods:

and one in-memory object class which functionsas an interface between BCS and its backend datasource:

Those two are linked by object's type Name:

reference: http://www.screencast.com/users/jthake/folders/SharePointDevWiki.com%20Screencast/media/10d81c1f-2bbf-417f-a307-1e88933b2864

Programming LINQ in VStudio 2010

  • LINQ to sql class
Programming LINQ to SQL in VStuido 2010 is as simple as step 1, 2, 3:
Step 1: launch VStudio 2010 to create an empty SharePoint Project:

Step 2: add a new item and choose LINQ to SQL Classes. Name it AWEmployee.dbml

Step 3: launch Server Explorer to drag Employee tables into design surface. In AWEmpolyee.designer.cs, you will find a class named as AWEmployeeDataContext.

  • LINQ to SharePoint
Just as SharePoint lists can now be displayed in VStudio 2010's Server Explorer, LINQ to SharePoint is another indication that MS start to treat SharePoint as a datasource. LINQ to SharePoint is not as mature as LINQ to SQL nevertheless. Currently it needs a manual process(as compared to the VS build-in entity framework for sql) , but fairly simple, to implement it:

Step 1 use SPMetal utility to generate a datacontext or entity class, for eaxmple: SPMETAL /web:http://sp2010/ /namespace:sp2010 /code: EntityClasses.cs

Step 2: the resulting source file defines a datacontext class which in turn defines an inner class for each individual SharePoint list (update 04/19/2010: or using parameters tag to define what you need to generate: /paramters:parameters.xml, see here for details) Add this file into VStudio project;

Step 3: Start query SharePoint List data by using LINQ query such as:
var query= from c in EntityClassesDataContext.Contacts where !c.ListName.Equal(""); orderby c.FirstName select c;
The advantage of using LINQ is, they are all strongly typed, and you get all intellisense.


Feb 11, 2010

Colon a SharePoint web application

I was asked to colon a web application, essentially this is just to backup/restore content db. sounds very simple? but a couple very costly pitfalls:

First, if new web app resides in the same farm, the challenge is, each collection Id has to be unique.
  • use stsadm addcontentdb to assign a different id, but as warned by MS, the site collection very likely becomes an orphan;
  • use stsadm backup/restore for each individual site collection;

Second, it is very tempting to take this shortcut: create a web application and then do content database backup/restore. This is an absolute failure path since SharePoint Config DB is left out totally.

The working path is:
  • Restore the content DB (if in the same SQL instance, file names need to be changed)
  • creating a new web application in a different farm, use the restored db to replace the one randomly generated by SP
  • after web application being created, use stsadm -o addcontentdb cmd line or UI to add the restored db, and then remove the one auto-generated by SP.
whether stsadm or UI, the credential needs to have access to the database. In case of UI, it is farm account(running central admin pool) and of course it is logon user account for stsadm. SharePoint will grant all other pool ids (such as application portal pool id) for the database access.