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

Anyone who has 'attended' a physical meeting by 'conferencing in' in knows the frustrations & limitations that come from not being in the room. You're the voice in the ceiling & not equally represented in the conversation.

This is no longer acceptable.

http://ow.ly/EmFK50Fqqhu

Today, we find ourselves facing the “hybrid work paradox.”

Employees are keen to retain flexibility. At the same time, human-to-human collaboration remains important.

To marry the best of both, hone your strategy, spaces, & tech to suit employee needs.

http://ow.ly/JtVO50Fn8qX

It's the day of the show, y'all!

Join the #PixelMillWebinars this morning at 11am PST for a live panel discussion about what the #digitalworkspace looks like for a #hybrid team, & how #Microsoft365 can empower your users no matter where they're working.

http://ow.ly/q81i50FhITy

IT'S WEBINAR WEEK!

Join the #PixelMillWebinars this Thursday as we welcome key players from @OrchestrySoft, @KieferConsult, and @AP_Mortgage to discuss the hybrid work paradox and how #Microsoft365 can empower your users no matter where they're working.

http://ow.ly/2uc550FfqO6

We've all been itching to get "back to normal," but what does that mean? Are we missing out on valuable lessons learned by trying to return to something that perhaps wasn't working before?

Join us next week for a live panel discussion on the new normal.

http://ow.ly/CfsU50FdQXv

Subscribe to PixelMill's
E-news

* indicates required

Let's Talk Digital
Workspaces Today

Get In Touch