Office 365 brings a wealth of new possibilities to the development community. In a recent article, Hong Kong alone saw a 250% increase in new customers since the Office 365launch in June last year. For the SharePoint community, Office 365 provides the “SharePoint Online” program built upon SharePoint 2010 technology.
One of the many capabilities of the SharePoint 2010 technology is the ability to create visual components called Web Parts to display various bits of information. SharePoint Online provides this capability, although in a limited capacity called “Sandbox Solutions.” For more information about Sandbox Solutions and their capabilities (and limitations) see Sandbox Solution Considerations MSDN, and Understanding the SharePoint 2010 Sandbox Limitations Wictor Wilen.
As in any Web Part solution, it is built upon a collection of files and assemblies. In this article, I will discuss how you can create a Common Assembly that you can reuse in all of your solutions. NOTE: Although “common assembly” commonly means you can have just one instance of the assembly and reference it from many projects, one of the limitations of Sandbox Solutions is that they cannot reference another solution. This instead allows you to pre-build an assembly and quickly include it in multiple projects, saving valuable time.
So, how do you reference a common assembly in your package? I will use a simple example where the assembly outputs a Namespace text in a Web Part. In this article, I am using Visual Studio 2010 (Ultimate) on a machine where SharePoint is installed.
To start, you need to first create a Visual Studio solution similar to what is shown below:
The project Unknown.CommonLibrary is currently an empty SharePoint 2010 Project that will store all our common codes.
The project Unknown.HelloSharePointOnline is also an empty SharePoint 2010 Project that will display the results of the Unknown.CommonLibrary results in a Web Part.
I then create the file UnknownConstants.cs within the Unknown.CommonLibrary project:
Within the Unknown.HelloSharePointOnline project, I also created a file called HelloWebPart.cs:
Now within the project Unknown.HelloSharePointOnline, click on the node Package and select the Advanced tab at the bottom of the panel:
Click Add and choose “Add Assembly from Project Output…”:
Select “Unknown.CommonLibrary” with Safe Controls as shown below:
After that, right click at Unknown.HelloSharePointOnline project and select Package:
Your final output will be a *.wsp file. Open your Solutions Gallery in SharePoint Online and upload your new solution. Add your new HellowWebPart solution to the page and you will see it output the following:
I hope this article is helpful as you’re developing for SharePoint Online!