In this post I will show you how you can convert you SharePoint farm
solutions (.wsp) to solution that works with Office365/cloud.
Following is the road map from Microsoft that shows how
Microsoft is transforming Office product for every platform:
Picture copied from Microsoft Office365 Developer site.
It looks like we have now more audiences
(Developers) or we can say that we have more options to develop solutions that
target Microsoft Office product.
Following are the common tasks that we usually do when we develop
SharePoint Farm solutions:
1.
Site Definition
2.
Site creation
3.
Item Receiver code
4.
Feature (I.e. To create site columns, content
types, list or document library etc)
5.
Site Columns and Content Types
6.
List or document library creations
7.
Workflow
8.
File upload using Module
9.
Timer job
10.
Querying sites, lists and other SharePoint
objects
11.
Item creations in list
12.
Branding (customising master page, page layouts
etc)
13.
WebPart development
To convert Farm solutions code to cloud compatible we have
got following choices to host code:
1.
ASP.NET MVC application
2.
ASP.NET Web-Form application
3.
Console Application (for continues integration
environment)
4.
Windows Phone/Table client
5.
Php application
6.
Android / iOS application
I will start with Console application that query SharePoint
objects from On-Premise SharePoint farm as well as Office365. By doing this way
we can prepare ourselves for cloud.
Let’s start writing some code that works in both
environment.
bool forCloud = true; Console.WriteLine("Connecting to Office365 at https://your-tenancy.sharepoint.com..."); // Open connection to Office365 tenant ClientContext clientContext = new ClientCon-text("https://your-tenancy.sharepoint.com"); clientContext.AuthenticationMode = ClientAuthenticationMode.Default; if (forCloud) { //creating secure string SecureString password = new SecureString(); foreach (char c in Office365Password) password.AppendChar(c); clientContext.Credentials = new SharePointOnlineCredentials(Office365UserId, password); } else { //Comment this line if you want to use your default network credential clientContext.Credentials = new NetworkCredential("UserName", "Password", "Domain"); } Console.WriteLine("Executing query..."); //load web Web web = clientContext.Web; clientContext.Load(web); clientContext.ExecuteQuery(); //displaying title of the web. Console.WriteLine("Web title: {0}", web.Title); Console.WriteLine("Loading lists..."); ListCollection lists = web.Lists; clientContext.Load(lists); clientContext.ExecuteQuery(); foreach (List list in lists) Console.WriteLine("List title: {0}", list.Title); Console.WriteLine("Done.");
For on premise just set onCloud to false and rest of the
code would be same for both environment. After executing it will show web site
name and all lists within the site.
Using this simple technique we can develop app-part, which I
will blog soon, to show aggregated data from various lists in Office365.
In next post, I will show you how we can leverage ASP.NET
MVC application to host SharePoint CSOM code that will be used to create site
definition and other stuff.
That's it for now. Please leave your valuable feedback.
That's it for now. Please leave your valuable feedback.