Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Posted Friday, April 1, 2011 11:08 AM by CoreyRoth

You know by now that the cloud is hot and Microsoft says “we’re all in”.  That being said, there has never been a better time to push all of those chips forward and  jump on the bandwagon.  It’s time to get some experience with SharePoint Online / Office 365.  I know most people don’t have access to the Office 365 beta yet, but when it opens up, you should sign up for the public beta and start getting familiar with it.  If you haven’t seen SharePoint Online yet, check our my previous article which gives a quick tour of it.  I plan to write more about SharePoint Online in the future, so I figured the best place to start is with an introductory development article on building and deploying a web part.  My past series on building and deploying web parts to 2010 and 2007 are still the most popular articles on DotNetMafia.com.  Let’s take what we learned there and see how we deploy web parts to the cloud.

Before we get started, let’s reiterate what we’re working with.  With Office 365, your development scenario involves sandboxed solutions.  As you know, these solutions are deployed to the site collection level and offer a restricted subset of the SharePoint API.  If you are already confortable working with sandboxed solutions, you are in great shape to begin SharePoint Online development.

What does the development environment look like?  Well, you know that SharePoint 2010 VM you already have?  You’re looking at it.  Just like Azure, SharePoint Online development also used the “Over the fence” development methodology.  Meaning, you develop your code locally and then throw it over the fence and hope it works.  This may sound bad, but it’s really not a big deal and the Azure people have been doing it for a while.  AppFabric is close to Azure, but there is always a possibility of differences when you get it in the cloud.  As long as you build a sandboxed solution and don’t make use of unsupported features (i.e.: PerformancePoint, BCS, etc), more than likely your code will work when it gets to the cloud.  There may be things that you can do in a Sandboxed solution in SharePoint 2010 compared to SharePoint Online, but it’s far too early to tell at this point.  To get started developing web parts in the cloud, you pretty much need a copy of SharePoint 2010 (or SharePoint Foundation) installed somewhere locally.  This could be native on your Windows 7 machine or inside a virtual machine.  Wherever it is, you will obviously need Internet access to get your code to the cloud.

To get started developing in the cloud, the first step is to build the web part on your local SharePoint environment.  I won’t go through all the steps here, because most of them are the same from my article on 2010 Web Part Development.  However, I will go through the important steps.  The first step is to create a new Empty SharePoint 2010 Project in Visual Studio 2010.  Specify the URL to a local site on your SharePoint server.  Don’t use the address of your SharePoint Online site.  It won’t work.  When prompted for the solution type, choose Sandboxed Solution.

SPOVisualStudioSandboxedSolution

At this point, you have a regular SharePoint project in Visual Studio.  Add a web part to the project just like you would in SharePoint 2010.  Sticking with the Hello World type example, we put some code like the following in our web part.

using System;

using System.ComponentModel;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using Microsoft.SharePoint;

using Microsoft.SharePoint.WebControls;

 

namespace SharePointOnlineProject3.HelloCloudWebPart

{

    [ToolboxItemAttribute(false)]

    public class HelloCloudWebPart : WebPart

    {

        protected override void CreateChildControls()

        {

            Controls.Add(new Label() { Text = "Hello, Cloud!" });

        }

    }

}

At this point, we can test our code locally on our SharePoint server.  Build and deploy the project and then add your web part to a test page on your site.  Again, if you aren’t familiar with these steps, take a look at my Building and Deploying Web Parts with SharePoint 2010 post. If the code, works you should see a similar page like the one below.

SPOHelloCloudWebPartLocal

Now, we’re ready to send our web part “to the cloud!”.  How do we do that?  Start by using the Package menu to build a SharePoint package (.wsp file). 

SPOVisualStudioPackageSolution

This creates a .wsp file located in the bin folder of the project.  We’ll use this file to deploy our web part to the cloud.  It’s now time to open up a browser and connect to your instance of SharePoint Online.  Once you get there, we deploy a sandboxed solution just like we would on-premises.  Go to Site Settings –> Solutions to view the Solutions Gallery.  Click on the Solutions button in the ribbon, and then click Upload Solution.  Browse to the bin folder of your Visual Studio project and select the file ending in .wsp.  Once it uploads, be sure and click the Activate button. 

SPOSolutionActivate

Now, you just need to ensure the feature is activated by going to Site Settings –> Site Collection Features.  If it is not activated, click the activate button.

SPOFeatureActivated

Your web part has now been thrown over the fence and deployed to the cloud!  Test it out by going to any page on the site and adding the web part to the page.  You’ll find your web part in the Custom section by default.  If all goes well, your web part should work here too.

SPOHelloCloudWebPartCloud

Congratulations, you have now deployed code to the cloud!  It’s really not that hard is it?  Now, you might be wondering if you can debug your solution.  Unfortunately, the answer is no.  If you have an issue, you have to step through it locally on your on-premises SharePoint server.  That’s all there is to getting started with SharePoint Online development.  As you can see it’s very familiar to sandboxed solutions development with your on-premises server.

Comments

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Thursday, April 7, 2011 4:20 PM by Tom Resing

Good stuff, Corey. I'm glad to see a step by step walkthrough on this before it's generally available. I'm sure we'll be seeing a lot more Sandboxed Development projects after Office365 is released and catches on.

-Tom

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Thursday, April 7, 2011 4:30 PM by CoreyRoth

@Tom Thanks!  Yes, it's time for people to get comfortable with sandboxed solutions if they have been avoiding them. :)

# SharePoint Kaffeetasse 233

Monday, April 18, 2011 8:39 AM by Michael Greth [SharePoint MVP]

Office 365 Office 365 How to: Build and Deploy a Web Part with SharePoint Online Office 365 How to: Create

# Начинаем разрабатывать для Office 365

Wednesday, May 4, 2011 1:39 AM by Dmitry Andreev

Примерно пару недель назад был сделан анонс Office 365 beta и некоторые счастливчики уже получили приглашение поучаствовать в тестировании. Российским представительством Microsoft по этому поводу даже был выпущен пресс релиз в котором заявлено что Office

# ???????? ???????????????? Microsoft / ???????????????? ?????????????????????????? ?????? Office 365 | News From Earth

Pingback from  ???????? ???????????????? Microsoft / ???????????????? ?????????????????????????? ?????? Office 365 | News From Earth

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Wednesday, May 18, 2011 9:12 PM by Thomas Trung Vo

Step by step to create a Sandbox Solution WebPart for SharePoint Online (Từng bước cách tạo một SharePoint WebPart sao cho có thể chạy trên SharePoint Online)  sharepointtaskmaster.blogspot.com/.../step-by-step-to-create-sandbox-solution.html

# MVPs for SharePoint 2010: Debugging Techniques for SharePoint Online Applications

Tuesday, May 31, 2011 5:13 PM by The Microsoft MVP Award Program Blog

Editor's Note: The following is a guest post by SharePoint Server MVP Corey Roth as part of the MVP Award Program Blog's "MVPs for SharePoint" series. Corey Roth is a solutions architect at Stonebridge specializing in SharePoint solutions in the Oil &

# MVPs for SharePoint 2010: Debugging Techniques for SharePoint Online Applications - MSDN Blogs

Pingback from  MVPs for SharePoint 2010: Debugging Techniques for SharePoint Online Applications - MSDN Blogs

# MVPs for SharePoint 2010: Debugging Techniques for SharePoint Online Applications - Bilim-Teknoloji | Positive Pozitive.NeT

Pingback from  MVPs for SharePoint 2010: Debugging Techniques for SharePoint Online Applications - Bilim-Teknoloji | Positive Pozitive.NeT

# MVPs for SharePoint 2010: Debugging Techniques for SharePoint Online Applications - Akl??ma Tak??lanlar | Zeytin.Net

Pingback from  MVPs for SharePoint 2010: Debugging Techniques for SharePoint Online Applications - Akl??ma Tak??lanlar  | Zeytin.Net

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Thursday, June 30, 2011 2:34 PM by Colin

fabulous, clean and clear guide, Thanks

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Wednesday, August 10, 2011 3:00 PM by matt herb

can you upload these to office 365 public sites? Seems not possible.  

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Wednesday, August 10, 2011 3:11 PM by CoreyRoth

@Matt I haven't tried it but it seems like you should be able to.  Remember you can just add t /_layouts/settings.aspx to your public URL.  From there you can get to the solutions gallery at /_catalogs/solutions/Forms/AllItems.aspx.

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Wednesday, September 14, 2011 5:45 AM by Thommy

This looks perfect, but when i try to add the webpart to some page, it gives me an error "exception in the method 'execute' of the sanbox-codewrapper" (sorry, my error message is in german). Any ideas?

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Thursday, September 15, 2011 5:26 PM by CoreyRoth

@thommy there may be some unsupported code in the sandbox web part.  You might try starting over with a basic web part or removing any code that looks like it may require more permissions that allowed with SharePoint Online.

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Thursday, December 22, 2011 8:52 AM by Shashank Sharma

This is one of the best articles so far I have read online. No crap, just useful information. Very well presented.  Thanks for sharing with us. Its really helpful for beginner as well as developer. This link also explained very well about how to create and deploy webparts in sharepoint.

mindstick.com/.../9e1d1fe1-7e51-4d01-86ec-f1f679631a7e

# How to: Use Visual Studio 11 to publish solutions to SharePoint Online - Grid User Post

Wednesday, January 11, 2012 5:38 PM by Office 365 Technical Blog

Audience: Office 365 for professionals and small businesses Office 365 for enterprises

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Tuesday, February 14, 2012 4:08 AM by Marcus

Thanks Corey, I was just checking out if I could load custom webparts to office 365 and I'm happy to hear I can!

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Thursday, July 12, 2012 12:56 PM by Shri

Hi Cory,

Thanks for the great post. I want to make use of the Skydrive for my storage. How do I interact between Office 365 site content and skydrive?

Thanks

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Monday, August 6, 2012 3:46 PM by CoreyRoth

@shri I am afraid there is no out-of-the-box integration between Skydrive and Office 365.

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Friday, July 5, 2013 1:04 PM by Ofer Gal

Do you know if 365 allows calling WSDL web service calls from inside a sandbox solution?

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Tuesday, July 16, 2013 10:45 AM by CoreyRoth

@Ofer Gal I don't know that it is supported from a sandbox solution.  The services are there, but I would be hesitant to develop a solution using them since they are deprecated now.

# re: Office 365 How to: Build and Deploy a Web Part with SharePoint Online

Wednesday, May 14, 2014 8:15 AM by Sumathi

Hi Roth,

I am having sharepoint 2010 wsp.I want to deploy this WSP into Office 365. Could you please help me on this.

Thanks in advance.

Leave a Comment

(required)
(required)
(optional)
(required)