Mar 12, 2013

Get Rid Of The MySite “Let’s Get Social Dialog”

When you open your MySite for the first time, the following welcome dialog gets shown:

image

The by default checked “Let’s get social” option changes the privacy of all your social activities to “everyone”. It is easy that somebody clicks accidentally okay. In Germany most work committees don’t like the fact that this may could happen.

You can easily deactivate the such called first run experience through the following setting on the my site host’s web property bag:

image

Key: urn:schemas-microsoft-com:sharepoint:portal:profile:SPS-O15FirstRunExperience
Value: OFF

Or via PowerShell:

$web = get-SPWeb http://mysitehost
$web.Properties[“urn:schemas-microsoft-com:sharepoint:portal:profile:SPS-O15FirstRunExperience”]=”OFF”
$web.Update()

Jul 23, 2012

Building ASP.NET MVC based SharePoint Cloud Apps

When you either create an auto-hosted or a provider hosted app, Visual Studio automatically generates an ASP.NET Forms project for you. Do you really want an ASP.NET Forms project? Many web developers would say no! They would prefer ASP.NET MVC. Anyway each of this two models has his advantages and disadvantages. Discussing this in detail would be out of scope for this post. Personally I think ASP.NET MVC and SharePoint Apps fit together really good. In this post I’m going to show step by step how to create an ASP.NET MVC based SharePoint app.

Create the SharePoint App

Create either an auto-hosted or provider hosted SharePoint 2013 App. For this example I’ve chosen auto-hosted. As development system I use a local Visual Studio with an Office 365 developer site.

image

Visual Studio will generates the following solution structure for you. Including a SharePoint App project and an ASP.NET Forms Web project.

image 

We prefer ASP.NET MVC. So let’s add an ASP.NET MVC (.NET 4.0) project to the solution. The Azure tenant currently supports only .NET 4.0.

SNAGHTML24bc897

SNAGHTMLb72629

In the SharePoint App property windows choose the ASP.NET MVC project as that associated web project.

image

One of the most challenging tasks of app development is the authentication. To help you with this Microsoft added a Token Helper class to the auto-generated ASP.NET Forms project. We want use the Token Helper too, so let’s copy the TokenHelper.cs file to our ASP.NET MVC project.

image

If you want to, you can change the namespace of the TokenHelper.cs to fit the project default namespace.

To be able to build the project you need to add some new references to the ASP.NET MVC project.

  • Microsoft.IdentityModel
  • Microsoft.IdentityModel.Extensions (if you don’t find the reference, copy the path from the ASP.NET Forms project and choose browse in reference dialog)
  • System.IdentityModel

This is be able to build again. But it very likely that you also want to callback to SharePoint, so add the references for the ClientOM.

  • Microsoft.SharePoint.Client
  • Microsoft.SharePoint.ClientRuntime

You have to set the copy local property of all the above references to true. 

We also need to enable SSL on our MVC project. If we would forget this, SharePoint would not send a Context Token. OAuth 2.0 requires SSL.

image

It is also useful to set the MVC project to “Don’t open page…”

image

Right click Controllers folders in the MVC project and add a new controller.

SNAGHTMLda8c0d

Add the following code to the controller:

image

Within the Views folder create a new sub folder called “Home”. Right click the folder and choose and add a new View:

image

Add the following code to the view:

image

Set the start page of our app to this view. To do this you have to switch to the code view of AppManifest.xml.

image

Now you can start the app for the first time. Hit F5, trust and start the app.

image

You have just created your first ASP.NET MVC based SharePoint App.

Note that during the first run Visual had added a Client Id and a Secret to the web.config of our ASP.NET MVC project.

image

When everything works as expected you can now delete the old ASP.NET Forms project.

Add SharePoint Look and Feel to the App

We are now going to add the ShareCoint chrome to our MVC site. Under Views->Shared modify _layouts.cshtml as follows:

image

Don’t panic, you can download the source code here.

Right click the app project and click deploy to deploy the app to Office 365. In the background tha ASP.NET MVC project will automatically provisioned to Windows Azure. The app should now look like this:

image

Wish you a lot fun with SharePoint Apps & ASP.NET MVC.

Cheers,

Christian

Jul 20, 2012

SPThumbMaker-Example for an Auto-Hosted Azure SharePoint App

To dig a little bit deeper into the possibilities of auto-hosted and provider hosted SharePoint 2013 apps, I’ve created a small example called “SPThumbMaker”. The app generates thumbnails for images that are stored in a picture library on the host site. To see how to get started with Auto-Hosted Azure apps read my previous post or the post Creating Provider Hosted Apps from my MVP mate Thorsten Hans.

Extend the Ribbon and the ECB to add the actions for the thumbnail generation

Ribbon Button “Create Thumbnails”

image

ECB Action

image

Elements XML of the two actions:

image

To only show the actions in picture libraries only I registered the actions on the list template type 109 (Picture Library). The “~remoteAppUrl” token points to the dynamically hosted ASP.NET site. Because my ASP.NET site must know for which image it should generate templates I’ve also appended the tokens “{ListId}” and “{ItemId}”. Beside the “~remoteAppUrl” token there is no difference to how you to SharePoint 2010 ribbon extension. But there this one restriction:
You can’t make use of JavaScript in the CommandAction. This is not allowed by design.

Get SharePoint Look and Feel on your ASP.NET Site

To integrate remote apps seamless into SharePoint the product team added the possibility to add the SharePoint chrome to our remote app.

Add the jQuery and ASP.NET AJAX Libraries

image

Dynamically load the “SP.UI.Controls.js” script. The scripts contains everything you need to render the SharePoint chrome on your site. This way you can load any other SharePoint script and CSS from within your app.

image

Render the SharePoint Chrome. You can customize the chrome via the options parameter. For example set the icon, title, add links…

image

Add a div container to render the chrome

image

Now the site header looks like this Smile

image

Server-side Thumbnail Generation

The generation works as follows:

I in the code behind of the ASP.NET form I extract the URL parameters, valid the SharePoint Context Token and get an OAuth AccessToken.

image

In the markup of the page I render image tags with a dynamically generated urls to a custom HttpHandler that generates the thumbnails.

image

I append to the URL all the parameters that I’ve got from the action (SPHostWeb, ListId, ItemId), the AccessToken and the size of the thumbnail.

image

In the HttpHandler I extract the query parameters and use the AccessToken to get a CSOM ClientContext to load the target  image from the host site and generate the thumbnail.

image

Finally the result looks like this

image

I hope this post helps to get a little bit better understanding of what you can do with auto-hosted and provider hosted apps.

You can download the source code here.