The Proper Web Part Control Class for a SharePoint 2010 Sandbox Solution

This post is one post in a series of posts I penned in hopes it would help those looking to move a SharePoint 2010 Visual Studio 2010 farm based solution to a sandbox. There are many gotcha’s and pitfalls that you may run into or you may want to be aware of. You can learn more about this series here as well as download the CodePlex Project, From the Farm to the Sandbox, which includes the sample farm and sandbox solutions references through this series.
The related posts include:
Automatically Check In Files in a SharePoint 2010 Sandbox Feature Event Receiver
SharePoint 2010 Sandbox Feature Deactivation – Removing Module Assets
Custom Properties in a SharePoint 2010 Sandbox Web Part
Why CSSRegistration Will Not Work in a SharePoint 2010 Sandbox Solution
Link to JavaScript Files in a SharePoint 2010 Sandbox Solution

Different Types of Webparts

When you create a web part in a SharePoint project that was original built as for a farm solution, Visual Studio will assume that your web part will inherit from Microsoft.SharePoint.WebPartPages.WebPart. This is great because then you have access to more specific SharePoint web part properties and functions such as overriding the web part’s GetToolParts() function (public override ToolPart[] GetToolParts()) so that you can build your own ToolParts (Microsoft.SharePoint.WebPartPages.ToolPart).
SharePoint sandbox solutions do not have access to Microsoft.SharePoint.WebPartPages.WebPart nor Microsoft.SharePoint.WebPartPages.ToolPart, so you instead need to make sure that your web part inherits from System.Web.UI.WebControls.WebParts.WebPart. In fact it is now considered best practices to always have your web parts inherit from System.Web.UI.WebControls.WebParts.WebPart so that you can move it to SharePoint online, or to other environments.
So the key is, a web part for a SharePoint Sandbox must inherit from System.Web.UI.WebControls.WebParts.WebPart. In general this should not be a problem. I will describe how to replace a custom ToolPart control in the next post.

Visual Web Parts and Sandboxes

There is no OOTB Visual Web Part that is compatible with a sandbox because part of the visual aspects are required to be installed to the server hive. But not to worry, there are some great work-arounds. I suggest the following article from MSDN.
For a complete review of the Farm and Sandbox solutions’ Feature Event Receiver, please reference From the Farm to the Sandbox for the full code. Also, please do not forget to check out the other posts in this series, all related to converting a farm solution to a sandbox solution.

Leave a Comment

Your email address will not be published. Required fields are marked *

Enter Code *

Filed Under

Related

Are you preparing to launch a new #SharePoint intranet?

Don’t spring it on employees out of the blue. First, talk to as many of them as you can.

Planning is just phase one. For all of our tips, watch our recent webinar!

http://ow.ly/dsQM50GqPI5

It's that time again! Join #Microsoft MVP & Regional Director, @EricOverfield on Thursday, October 28th, at 11:00 AM PST as he walks through #MicrosoftViva’s current state & offerings and what they mean to your #digitalworkspace right now.

http://ow.ly/3QFK50Gnx9f

It's the final countdown! Join @EricOverfield at 11am PST to learn about common pitfalls and paths to success when moving to #SharePointOnline. You'll walk away with practical tips to use in your organization today!

http://ow.ly/fdf150GjyJT

In today's episode of the #PixelMillWebinars, you'll learn from the experience of a global organization’s path to digital teamwork victory and get to see first-hand how to successfully plan a smooth migration for your team.

Join us at 11am PST!

https://pixelmill.com/webinar-9-takeaways-from-a-global-organizations-migration-to-sharepoint-online/

It's the day of the show y'all! Join #Microsoft RD +MVP @EricOverfield at 11am PST as we walk you through a multi-national enterprise software company’s migration journey to #SharePointOnline. Learn about common pitfalls and paths to success.

http://ow.ly/cN9250GjtGk

Subscribe to PixelMill's
E-news

* indicates required

Let's Talk Digital
Workspaces Today

Get In Touch