Category Archives: SharePoint

SharePoint app tools in Visual Studio 2013 preview, the new SharePointContext helper!

imageToday at the build conference  the new preview of Visual Studio 2013 was released.  Along with it there were some nice advances in the tools for building SharePoint and Office applications also.

You can read the full post about the tools here.

The most interesting of these is the new out of the box project template option for creating a ASP.Net MVC based application.  It asks you during the project creation wizard for provider hosted and autohosted apps.

image

When you create a totally out of the box app using the wizard and picking this setting you get a very familiar looking app if you have ever create an ASP.Net MVC app before.

image

Now that is pretty handy being able to create these via the wizard, but what is even cooler is a particular improvement to some of the additional helper classes you get in the new template.

Namely the SharePointContext class.

This is a new class that is added in the new out of the box template is helps you manage your SharePoint context across page requests.

image

When SharePoint “starts” an app i.e. when a user launches an app, SharePoint packs up some information about that user and passes it along to the app as a POST parameter. This is called the ContextToken and it contains OAuth tokens/information that you need in order to make calls back to SharePoint. Now the trick is that SharePoint passes it to your app when it launches and then it is up to you to do something like cache it so that in subsequent page requests your app has that context and can reuse it.  The basic auth token in it is good for 12 hours & it also contains a refresh token that can be used to get new auth tokens for up to 6 months.

The first question people that are new to SharePoint app development ask me is “my app breaks on the second page request, why?” … it is usually because they don’t realize its totally up to them to cache these very important tokens.

The new MVC template in the VS 2013 preview includes the SharePointContext class that helps with this whole process & gives you an out of the box experience that doesn’t totally suck.

In a new project you will see a line of code that looks like this:

var spContext = SharePointContextProvider.Current.GetSharePointContext(HttpContext);

This is creating a new context object & initializing it using all that good information passed as a POST parameter and some querystring parameters too.

Then you can use that context to get Client Side Object Model (CSOM) instances really easily like this:

using (var clientContext = spContext.CreateUserClientContextForSPHost())
{
    if (clientContext != null)
    {
        spUser = clientContext.Web.CurrentUser;

        clientContext.Load(spUser, user => user.Title);

        clientContext.ExecuteQuery();

        ViewBag.Message = spUser.Title;
    }
}

Now this is not all that different from what you used to do on the first request to your SharePoint app.  TokenHelper helped you create a CSOM instance from the request details. However the SharePointContext goes further.

When you make the GetSharePointContext(HttpContext) call the class checks the ASP.Net Session state for an existing context. If it doesn’t find one then it creates a new one based on the information passed and then stashes it in Session state for subsequent requests.

Then on subsequent requests, when SP hasn’t passed any new tokens, the GetSharePointContext(HttpContext) will return you back the context from Session state. It will also deal with when and if tokens expire.

(Update 6/28 – added this paragraph)
Additionally the provided [SharePointContextFilter] attribute on controller actions ensures a context is passed from SharePoint. If not it will redirect the user back to SharePoint to obtain one.  Why is this important?  Well, if someone bookmarks your app then when they use that bookmark the context wont be passed & in that case you need to bounce them via SharePoint to go and get one for the first request.  The [SharePointContextFilter] automates that for you.  This is only available in the MVC project however. Very handy indeed not having to wire up this flow yourself!

You don’t need to worry about writing any of this however, as it is all done for you in the helper class.  Go take a look in the GetSharePointContext(HttpContextBase httpContext) method if you are interested in seeing how it works & more importantly run your app and set through the code so you can see how it runs and works.

Once you have a SharePointContext object you can take a look in it and find the CacheKey (used for uniquely identifying this in the cache), ContextToken (for making calls back to SP), RefreshToken (for getting more access tokens when they expire) and other properties it stashes for you like the site language, SP product version etc…

image

The way in which it is structured is also very friendly for replacing if you want to roll a different caching technique.  You could replace the existing implementation or create your own SharePointContextProvider class that managed the caching.

The library comes with implementations for both on-prem and cloud scenarios:

  • SharePointAcsContextProvider – Office 365
  • SharePointHighTrustContextProvider – On-Prem apps using the high trust S2S auth model

Summary

This is simple but very timely additional to the out of the box templates in VS!

Just a few weeks ago at TechEd North America I did a tips and tricks session for app developers and Demo #2 was showing a simpler version of essentially the same thing.  The main difference in the helper class I showed in that demo was that it will work for ASP.Net forms apps as well as MVC (Update 6/27: The newly shipped helper does support ASP.Net Forms based apps too) … however it doesn’t deal with the high-trust S2S scenario for on-prem only apps.

Shout out to @chakkaradeep for the great work on the VS SharePoint tools (a topic near and dear) & for taking the time to watch my TechEd session and let me know they were releasing this helper today!

Update 6/27/2013: Mike Morton did a great session at build yesterday that walks through a whole lot of this. What it here: http://channel9.msdn.com/Events/Build/2013/3-319

To try this out for yourself you will need to get the VS 2013 preview bits: http://www.microsoft.com/visualstudio/eng/2013-downloads

You will also need a SharePoint site to try it out in and I recommend signing up for a trial Office 365 site here: http://msdn.microsoft.com/en-US/library/office/apps/fp179924

Thanks!

-CJ

ShareIt for Office 365 is published

imageMy previous post “Integrating SharePoint Online and Yammer – an app for that!” talked about an app we were building that would help you post a document that lives in SharePoint to Yammer.  The document stays in SharePoint but a link to the document is posted to Yammer where the conversation and discussion about it can continue i a highly collaborative setting.

ShareIt for Office 365 just hit the marketplace.  For free! If you use Office 365 and Yammer then this is a must have tool for your site.

It’s really simple to use.  Select a document and click Post to Yammer.

image

We have a raft of enhancements that we are hoping to make to the product over the next few months.

You can find out more about the app in the Office marketplace here:
http://office.microsoft.com/en-us/store/shareit-WA104088567.aspx

As always feel free to get in touch with me on twitter @LoungeFlyZ if you have any questions.

Thanks,

-CJ.

Using SharePoint VMs in Windows Azure with VPN access

At TechEd North America 2013 my good friend Paul Stubbs did a session with Michael Washam and Corey Sanders on:  IaaS: Hosting a Microsoft SharePoint 2013 Farm on Windows Azure

This was a really cool session that focused on building out SharePoint farms in Azure.  One of the things they talked about was a set of PowerShell scripts that they have built to fully automate this process.

The “SharePoint 2013 Automated Deployment Master Scripts” is a set of scripts that you can grab from GitHub that will automate end to end the process of creating, configuring and setting up SharePoint in Azure IaaS VMs.  They let you build out two farm types right now:

  • Single VMs – 3 VMs (DC, SQL and SharePoint)
  • Highly Available – 9 Vms (DC x2, SQL x2, 1 Quorum VM, SP App servers x2, SP WFE x2)

I watched the session in the online recordings after the TechEd and it interested me enough to try it out. 

So I did! and I have to say it totally rocks!

The PowerShell all runs on your client machine and uses the Azure PowerShell Cmdlets to remotely setup Azure etc… Getting your machine setup before you run the scripts is a little tricky as it uses CredSSP for delegation which requires some manual setup, but if you follow the Wiki word for word you should be fine (here).  My CredSSP setup failed because the Windows Remote Management service wasn’t running.

image

I wont get into all the steps for how to set up and run the scripts as that is well documented:

https://github.com/WindowsAzure/azure-sdk-tools-samples/wiki/Automated-Deployment-of-SharePoint-2013-with-Windows-Azure-PowerShell

After you run the scripts you end up with a fully configured SP Farm running in Azure.  Nice!  I opted for the SingleVMs option … so 3x VMs in total.

image

All those VMs sit on a Virtual Network that is also configured for you:

image

Once the whole script has run (warning can take a couple of hours) you can RDP into the VMs … or, just navigate to the default Sharepoint site that is configured. The script also outputs the admin credentials and the sites that were created:

Credentials: corp\spadmin Password: *********
Created Farm on http://sp-foo.cloudapp.net
Created Admin Site on http://sp-foo.clouadpp.net:20000

If you are looking for a quick and easy way to get started with building a SharePoint environment out on Azure then this is a great way to get started.

The next thing I wanted to do was to connect my personal machine into the same virtual network that the VMs run on.  Azure provides the ability to set up a point-to-site VPN that lets you do this.  Once you have configured this you will end up with a VPN connection from your machine into the network with your VMs in Azure.  This makes working with the whole setup a bunch easier and you can use your local machine for development and connect to the farm seamlessly.  You could even join your machine to the AD Domain that was automatically created for you if you wanted.

I did this & although its pretty complex it was pretty neat to finally get up and running.

A good starting point is this guide: Configure a Point-to-Site VPN in the Management Portal

HOWEVER!  One of the steps in that guide is creating a Gateway.  This is the VPN endpoint that your client PC connects to.  However, the steps in that guide assume you are creating a new  virtual network whereas in my case the virtual network was already created.  This means the settings referred to in the guide above are not available!  In particular i couldn’t modify the “Configure point-to-site connectivity” checkbox as it was disabled.  This took me quite some time to figure out.

First you need to Export your configuration using the Export button on the Virtual Network:

image

Then you need to modify the Export XML file and add the bits in bold below:

  <VirtualNetworkConfiguration>
    <Dns>
      <DnsServers>
        <DnsServer name=”DC1″ IPAddress=”10.20.2.4″ />
      </DnsServers>
    </Dns>
    <VirtualNetworkSites>
      <VirtualNetworkSite name=”SPAutoVNet” AffinityGroup=”SPAutoVNet-AG”>
        <AddressSpace>
          <AddressPrefix>10.20.0.0/16</AddressPrefix>
        </AddressSpace>
        <Subnets>
          <Subnet name=”AppSubnet”>
            <AddressPrefix>10.20.1.0/24</AddressPrefix>
          </Subnet>
          <Subnet name=”DCSubnet”>
            <AddressPrefix>10.20.2.0/24</AddressPrefix>
          </Subnet>
   <Subnet name=”GatewaySubnet”>
        <AddressPrefix>10.20.3.0/24</AddressPrefix>
    </Subnet>
        </Subnets>
        <DnsServersRef>
          <DnsServerRef name=”DC1″ />
        </DnsServersRef>
    <Gateway>
        <VPNClientAddressPool>
            <AddressPrefix>10.0.0.0/24</AddressPrefix>
        </VPNClientAddressPool>
    </Gateway>

      </VirtualNetworkSite>
    </VirtualNetworkSites>
  </VirtualNetworkConfiguration>
</NetworkConfiguration>

This adds a gateway subnet and an address pool for client PCs that connect via VPN.

Then you can reimport that configuration and your setup will be updated to include those settings.

image

Then you should see the point-to-site settings correctly setup like this:

image

You can then move on to creating the Gateway you need on that virtual network:

When you do that it can take a while to create the gateway … so be patient 🙂 it took about 10mins for me.

If that works correctly you will see your gateway setup properly along with its external IP etc…

image

Now comes the fun part … CERTIFICATES!  The VPN uses client certificates to authenticate and so you need to create and upload a root cert to Azure as part of this. These steps are detailed in the MSDN guide here: http://msdn.microsoft.com/en-us/library/windowsazure/dn133792.aspx#bkmk_VPNCertificates

It’s a bit fiddly, but in a nutshell you create a root certificate, upload it to Azure, create a client certificate off that root certificate & then load that on your client PC.  Below is my root cert uploaded to Azure:

image

Finally you get to the results of all your hard work.  You can download the VPN package which contains the configuration etc… from the Azure portal via a handy link:

image

Install it on your client PC … and once complete you should see a VPN connection available in the network area in Windows:

image

image

image

All going well you will be VPN’d into your Azure network and you should be able to ping the VMs! e.g. 10.20.1.5 is the main SP VM.

I went and created a new Web App in SharePoint on http://intranet, and the only other thing I did was add “intranet” to my hosts file on the client PC so it knew to hit 10.20.1.5 (the SP machine).

After that … boomtown! … my newly minted SharePoint site is available off my client PC via the VPN to Azure.

image

This is going to be very handy for playing around with various SharePoint farm setups in Azure with the flexibility of having them run in the cloud.  I don’t have a 32GB RAM laptop to do this “on prem” unfortunately. Azure VMs have only recently become affordable for me with the recent announcement that you don’t pay for them when they are switched off. 

Enjoy and thanks for reading.

Chris Johnson

SharePoint Intersections conference, MGM, Las Vegas, Oct 2013


Missing your yearly SharePoint fix in Vegas?  Look no further!

SharePoint Intersections is a new conference happening at the MGM Grand in Las Vegas, October 27 – 30.  They have a great set of sessions planned and its definitely worth taking a look at it.  ASP.Net, Visual Studio, Azure and SQL Intersections all happen at the same time in the same place … so its not just a bunch of SharePoint people to hang out with too 🙂

REGISTRATION DISCOUNT: Get a $50 discount!  Use the discount code “JOHNSON” during registration!

Bonus:  If you Register for the SHOW or COMPLETE package you get a Surface RT or XBOX or gift card!

I have the great privilege of running a one day pre-con workshop on SharePoint App development alongside Andrew Connell:

PRECON08: Getting Your Arms Around the SharePoint 2013 App Model (10/27 8:30am-4pm)

As well as the following sessions:

  • SP05: Working with SharePoint APIs Remotely

  • SP06: Apps for SharePoint Primer

  • SP04: Soup to Nuts how to Build a Metadata and Search Driven Intranet

For more information see: http://www.devintersection.com/sharepoint.aspx

I hope to see you there!

-CJ

Integrating SharePoint Online and Yammer – An app for that!

Way back at SPC12 (Nov 2012) the keynote included a demo that showed an example of the integration possible between SharePoint Online and Yammer that could be done with a little bit of development effort. I built that demo and decided to turn it into a real app anyone could use.

Some Background first: This surfaced in SharePoint Online by way of a new ribbon button that when pressed posted the selected document to Yammer via the Yammer Open Graph API.  It was shown pretty quickly and it was pretty easy to miss.  However, it demonstrated a few interesting methods of integration that are possible today using the new SharePoint App plumbing and Yammers pretty decent set of APIs.

The basic flow

1. In a document library a document was selected like this

clip_image002[4]

2. Then in the ribbon a new “Post to Yammer” button showed up

clip_image002

3. When it was clicked it posted to the Yammer activity feed. 

clip_image002[6]

The image above shows the hover over the activity. 

The activity feed shows a scrolling history of activity in the the Yammer network.  e.g. “Chris Johnson updated Product Catalog.docx”.  Its like that thing in Facebook that shows you all the music that your mates are listening to that they probably don’t know they are publishing to all their friends via spotify.  More on the Activity feed a little later on.

4. Clicking on the activity will take you a page in Yammer for that activity where you can Be Social™ and discuss the document, like it etc…

image

How it’s made

This app is pretty simple.  It’s a SharePoint Provider hosted application running in Azure Websites.  The SharePoint part of the app includes some xml to add the ribbon button to all document libraries.  When the user clicks the “Post to Yammer” button it sends some details about the document(s) to the backend of the app running in Azure. The backend code then uses the CSOM to call back into SharePoint to retrieve the name of the document and some other properties. Then the app directs the user through the Yammer OAuth authentication flow.  Once this is complete the app then is able to access Yammer on behalf of the user that signed in.

Finally the posting of the information includes posting to the Yammer activity stream using the OpenGraph APIs (JSON/REST based). It will also post to the main feed in Yammer too via the Messages REST API in Yammer. Both of these are easy to use and are fairly standard XML/JSON/REST based services.

image 

Why is this interesting?

Recently there has been a bunch of noise about SharePoint’s current dual headed social story. 

  • In the red corner you have the social features in SharePoint (both on-prem and SharePoint Online)
  • In the blue corner you have Yammer.

The problem is that right now there is much consternation about how they don’t work nicely together. Things seem to be happening too slowly for some people.  The products are currently not integrated all that well. That is slowly changing, like the ability to switch from the NewsFeed to Yammer in Office 365 that rolled out the day of writing this post.  Those improvements will continue over time and eventually I think we will see the ability to totally replace the current out of the box social features with Yammer.

<mini-rant>
How on earth people think Microsoft can magically mash together one product with another overnight and make it all work perfectly is beyond me. It will take time people! Just because you think you could have done in overnight doesn’t mean it works that way in huge software projects … better stop this rant now before i get carried away.
</mini-rant>

The short story is that right now you have to pick one or the other.  My vote is firmly in the Yammer category. But at the end of the day there are many factors that will go into your decision either way and there isn’t a perfect answer.

There is no doubt that Microsoft will integrate the two products more deeply.  This could come in a variety of flavors including:

  • surfacing stuff that happens in Yammer in SharePoint more seamlessly (short term strategy),
  • totally replacing the existing SharePoint social features with ones backed by the Yammer in the cloud (more likely and what I would put money on, maybe with the ability to use the old stuff if you can’t use a cloud service)

Back to why this integration is interesting…

You can do things today to help with this situation.  The demo showed a very basic example of some custom integration using things we know exist today.

I smell a set up!

… and you would be right.  We are going to release this app to the store so that anyone with Office 365 can use it.  It needed some tweaks to make it work well in production & some branding changes. However in the coming days/weeks we will release it under the name “ShareIt”.

image 

I am going to write a future post on how this app was created and it will include code to illustrate how to call the Yammer APIs.

Ultimately you should be able to follow along and learn about how you can leverage the SharePoint App model + Yammer APIs to help integrate the two products while we wait for MS to offer a nice compelling seamless integration at a yet to be determined point in time 🙂

Note: It is very likely that this app will no longer be needed once MS do their thing and integrate the products further.  I hope so to!

-CJ

TechEd North America session wrap up

image 

This morning at TechEd North America i did a session on Office and SharePoint 2013 App development.  In a nut shell it was 75mins of demos (8 or so).  It was a mix of things I have found handy developing Apps, things I think are going to play an important role in App development (SPA apps) and other things that I think are handy for those getting started with App development.

Here is a summary of the demos:

#1 SignalR:  Using SignalR in your apps backends for watching trace and debug information from your application. Great for when your code is running in Azure and you want visibility into what is going on.

#2 Token Caching: When you first are starting out with app development its not entirely obvious what all the tokens and parameters are that are passed to your app code. OR how to work with them.  This demo was all about showing a lightweight way to cache and store the tokens for use in subsequent pages.

#3 Use OAuth to access SharePoint from apps for Office:  This showed how to do “on the fly” OAuth from a task pane App in Excel.  This lets an application ask the user for permissions to SharePoint resources when needed. In the example i showed Excel, but you can do the same from a SharePoint app.

#4 / #5 The SharePoint cross-domain library: Two demos showing techniques for calling out to external services (in this case my blog) from JavaScript running in a SharePoint hosted app.  Also how to set up the CSOM for calling into the Host Web SharePoint site where you app is installed.  Both scenarios show cross domain techniques available.

#6 Bring Office documents into your SharePoint apps with the Office Web Applications:  Most people have seen the document preview windows you get in SharePoint search and document libraries that use the Office Web Applications. But you can also use these in your own Apps too.  Great way to show documents alongside your App content.

#7 SPA Apps:  Single Page Applications.  Very kindly Andrew Connell allowed me to show his recently built Learning Path Manager demo which showcases an App built using Durandal, Knockout, Bootstrap, FontAwesome, LinqJS and Toastr.  Finally SharePoint development has been possible using frameworks, tools and techniques that are moderns and current.  All the cool kids are doing this stuff and I think its going to be a very interesting option for SharePoint app development going forward. For source and more information please refer to AC’s blog post. 

#8 App CSS makes your app look like part of the experience: A simple demo showing how to use the Chrome Control and SP CSS in your provider hosted apps.  I skipped this in the session due to time.

#9 Elevate your SharePoint app’s permissions with app-only calls: No more running code in process as system!  The App model provides a fairly elegant way to elevate permissions without losing control of an apps privileges! Apps can make “app only” calls to SharePoint to do things that the App has rights to do, but not necessarily the user using the App.

#10 Yammer Integration – Bring your app to where users are by posting to the feed:  Yammer provides some nice APIs to work with.  For example REST APIs for posting the feed & OpenGraph APIs for posting activities.  I demoed an App called “ShareIt” that takes a document and posts it to Yammer. The app will hopefully be in the 365 marketplace shortly (free) and I hope to do a follow up “how it works” blog post on it + full source for the app.

Slides: (they are boring … just intros to the demos)

Demo files: The zip below contains the demo files for demos #1 – #6 and  #8 and #9.  SPA code comes from AC here and the ShareIt code (Yammer) will come out as part of my new blog on that App shortly.


The recording of the session will be up on Channel 9 in the next 24-48 hours i am told:
http://channel9.msdn.com/Events/TechEd/NorthAmerica/2013/SES-B401#fbid=vskrIEZiOtr

Happy App’ing!

-CJ

Puget Sound SharePoint User Group presentation – Stop! Yammer Time.

Last night i was fortunate enough to present to the local Puget Sound SharePoint User group at the Microsoft offices in Bellevue.  I titled my presentation “Stop!  Yammer time”.

It was all about Yammer (no surprise there).  I ran through where I thought things were at with regards to the current overlap and confusion between the out of the box SharePoint social features vs. those in Yammer, some roadmap information about what to expect over the next year with regards to the integration of the two products and also a few bits for developers on what APIs are available.  I also demoed a sneak peak of an app for SharePoint Online that we are publishing shortly that lets people post information to Yammer from SharePoint (more on that soon in a future post).

I was also a little antagonistic (trying to get people questioning and thinking a bit more) with my analogy between SP vs. Yammer and the Matrix movies Red pill vs. Blue pill decision that Neo has to make.  Blue pill, stay blissfully ignorant that Yammer isn’t the future of all things social in SharePoint and other Microsoft products, or the Red pill, take the painful truth of reality now and get ready for the future albeit painful and a bit messy for the time being.

It was a fun session and i really enjoyed the opportunity to present.

My slides are below if you are interested in taking a look.  (they don’t really articulate a lot of what i spoke about outside of the slides, but hopefully it helps a little)

-CJ

I’m presenting on SharePoint and Apps at TechEd North America 2013…

TechEd likely needs no explaining to most folks who read my blog, but in short it’s Microsoft’s big technical conference that covers pretty much all MS technologies and products under one roof.  It’s a great event for taking in a lot of different topics vs. a more product specific event like SPC.

This year it is in New Orleans from June 3rd – June 6th and I will be there doing a session on SharePoint and App development tips and tricks.

SBS-B401 : Tips You Need to Know for Creating Apps for Microsoft Office and SharePoint 2013

In this session, we cover some tools and techniques for building out apps for Microsoft Office and SharePoint, including architecting for cross-domain scenarios, types of apps and much, much more. This is a must attend session for all app for Office and SharePoint developers.

Thursday June 6th at 10:15 am – Room TBD

So if you are are a SharePoint person attending it would be great to have you come along … or just get in touch at the event to chat!

-CJ

I’m presenting at the SharePoint Evolutions Conference 2013 next week in London

I posted about how amazing this conference is previously and i am getting excited about heading to London on Saturday.

http://www.sharepointevolutionconference.com

I am presenting two sessions next week on Monday and Tuesday on the process of building SharePoint and the other on building modern intranets using search, metadata and blending the old style of hierarchical sites with newer techniques of search based solutions.

P&M308 – Leverage the power of metadata and search driven Intranets

Learn how to take all that chaos and clutter in your organization and move it to an organized discoverable system that enables users to quickly navigate and find documents and information that is most relevant to them.  This is a soup to nuts session on the design decisions, things you need to think about and how to build a purely metadata and search driven Intranet to unlock the full power of your content.

This session is going to be all about building Intranets using the same features and functionality everyone is talking about in 2013 for building public facing internet sites. aka Web Content Management (WCM).  I’ll discuss traditionally structured intranets, hierarchy and storage systems in SharePoint, authoring considerations & a model for blending the old style hierarchical intranets with modern search driven techniques! 

Come and hear how you can leverage some of these new techniques with the old to deliver a great experience for your users whether they like to browse, search or a mixture of both 🙂

-CJ.