Tuesday 3 April 2012

How to Create a Visual Webpart in SharePoint Sandbox Solution


I am sure you must be aware of Visual Webpart is not applicable in Sandbox solution when you try to add it on Visual Studio 2010.

But now you can install a Visual Studio 2010 SharePoint Power Tools to helps you resolve this problem, after installed just insert your new Visual Webpart (Sandbox) as normal.

But as Sandbox solution, this still has limitation which constrained by SharePoint Sandbox framework.

Here the link to download the Power Tools.

Tuesday 7 February 2012

Create a Page/Item in Ghosted Mode Programmatically


Have you ever encountered pages/items added to SharePoint library/list via feature with custom code is not ghostable? This is because when file or page is created under SP Object Model the SharePoint will save them as instance in content database. But when you provisioning those files via feature module then they will become ghosted. When you need a custom to provision file? Such as page is already existed, that is default page of site or etc.

Some of you may not know what ghosted mean in plain English,

"A ghosted page is a page in SharePoint website which is not stored in the database instead it reference to a file which exists in the server’s file system. These reference files are common for all the website/site collection within that SharePoint server, i.e., if you modify a reference file then that change will reflect in all the websites/site collections within that SharePoint server automatically. So we can say these reference files are used as template."


As you can see the benefits of having file which is ghosted when you are working in large farm or huge repository that referenced to same file.

The SP Object Model does not support adding file to SharePoint under ghosted mode, therefore after reflected Microsoft.SharePoint assembly and discover that is a way to perform same task as feature module does. "EnableModuleFromXml" in Microsoft.SharePoint.Library.SPRequest.

I had attached a helper class which hope it can help you along with your development.

Here the example when you try to use provision a file.


GhostFile("FullFeaturePathOnServer", [targetWebsite], [targetFolderRelUrl | "Or leave empty"], differentTargetFileNameOrNull, createListItem, mode)

Set createListItem = false when try provision item in list.

Tuesday 24 January 2012

SharePoint List View (Calendar) Webpart Cross Site/Web Rendering with No Code Hack


These scenarios more likely to happened when working on restricted environment such as no custom development and the SharePoint Designer is only tool available.

For instance,

"Calendar list cannot be shared across other site collection or subsite with Calendar view mode"

Or

"This webpart is only work on current website context and when it used on other website the information is not the same"

If above sound familiar then this little non-coding hack maybe useful to you.

Here the pre-requisites:
  • SharePoint Designer (2007 or 2010 depend on your environment)
  • Basic Html editing skill.
  • A new minified masterpage.
  • A new page inherit from new minified masterpage.
  • SharePoint Page View Webpart.

Some of you may already aware what have to be done with above pre-requisites. You are right, we are going to create a new webpart page without any branding and loaded with Page View webpart (Iframe).

Here the steps:
  1. Create a new masterpage without any branding but leave the main place holder.
  1. Create a new webpart page and point it to newly create minified masterpage. This page has to be create on website that you wish to share. e.g. http://yoursharepointsite.com/pages/calendar.aspx
  1. Insert the Calendar webpart into page just created in step 2.
  1. You are almost there, go to the page that require the Calendar webpart to render and insert the Page View webpart. e.g. http://yoursharepointsite2.com/pages/pagerender.aspx
  2. Point the newly inserted Page View Webpart to http://yoursharepointsite.com/pages/calendar.aspx.
  3. Walah, done.

Limitation
  • The website which consume the content is assume to have same access permission to source website, otherwise credential is require for login.