SharePoint 2010 Mobile Web Part development

January 17, 2010   22:15


mobiledevice For a SharePoint 2010 demo i’m building a web part that should be accessible by Mobile devices. In SharePint 2010 all mobile devices are redirected by default to the mobile SharePoint rendering engine.

The mobile rendering engine of SharePoint provides mobile users access to the sites with a completely stripped interface. Its main function is to list all libraries and to provide basic access to them. For wiki and blog sites the rendering engine also provides some content rendering.

To keep the amount of data as low as possible, almost all web parts are completely stripped from the mobile site. Only when a web part developer provided a special mobile version of the web part, the web part will be accessible in the interface and to keep the mobile screen as empty as possible, the user must first expand the web part via its title to see it.

Documentation about SharePoint Mobile development is provided at MSDN. At first it all looks quite complex, but building a mobile version of a web part is actually not that hard. Below I will explain the required steps with a ‘Hello world’ example. For this sample I will not rename the default object names provided by the Visual Studio templates.

(more…)

Tags: , , , , .





Enable item scheduling by code

May 18, 2009   21:29


Enable item scheduling by codeeI’m developing a site template, which requires item scheduling on the page library. I don’t want our users to enable the item scheduling manually at the “_layouts/ ManageItemScheduling.aspx” page. Unfortunately I was not able to find any online documentation about how to do this with code.

It required me to dig deeper and .Net reflector turned out to be the right way to go. Microsoft made a lot of the required functions internal, which means that we cannot access the functions from our own code. By analyzing the steps I was able to add item scheduling on the pages library with the code below.

Step 1: Enable Moderation and Minor versions
To allow item scheduling, we must enable moderation and minor versions on the pages list.

SPWeb web = new SPSite(”http://web”).OpenWeb();
SPList list = web.Lists["Pages"];

//Enable moderation and minor versions
list.EnableModeration = true;
list.EnableMinorVersions = true;
list.Update();

Step 2: Register Scheduling Events
The item scheduling requires us to register 2 events.
First we will retrieve the assembly and class information of the ScheduledItemEventReceiver and then we will create the 2 events.

//get type information
Type scheduledItemType = typeof(Microsoft.SharePoint.Publishing.Internal.ScheduledItemEventReceiver);
string assemblyName = scheduledItemType.Assembly.FullName.ToString();
string className = scheduledItemType.FullName;

//Get the eventreceivers
SPEventReceiverDefinitionCollection eventReceivers = list.EventReceivers;

//Register the updating event
SPEventReceiverDefinition updateDef = eventReceivers.Add();
updateDef.Name = “Item Updating Event Handler For Scheduling”;
updateDef.Type = SPEventReceiverType.ItemUpdating;
updateDef.Assembly = assemblyName;
updateDef.Class = className;
updateDef.Update();

//Register the added event
SPEventReceiverDefinition addDef = eventReceivers.Add();
addDef.Name = “Item Added Event Handler For Scheduling”;
addDef.Type = SPEventReceiverType.ItemAdded;
addDef.Assembly = assemblyName;
addDef.Class = className;
addDef.Update();

Step 3: Unhide the startdate and expirydate fields
The list already contains the startdate and expirydate fields, but they are hidden. With the following code we will unhide the fields.

//Get the field guids of the startdate and expirydate
Guid startDateGuid = Microsoft.SharePoint.Publishing.FieldId.StartDate;
Guid expiryDateGuid = Microsoft.SharePoint.Publishing.FieldId.ExpiryDate;

//update the visibility of the startdate
SPField startDateField = list.Fields[startDateGuid];
startDateField.Hidden = false;
startDateField.Update();

//update the visibility of the expirydate
SPField expiryDateField = list.Fields[expiryDateGuid];
expiryDateField.Hidden = false;
expiryDateField.Update();

And that’s it. With these coding steps we enabled item scheduling at the Page library.

Tags: , , , , .









The content expressed in this blog are those of Edwin Vriethoff and do not represent his employer's view in anyway. The contents of this blog has been carefully put together, but Edwin Vriethoff is not responsible in any way for any direct or indirect harm caused by individuals or organizations using the content of this blog in any way.