Monday, December 21, 2015

Whats new in SharePoint 2016 Remote API Part 2 (Sharing)

Technorati Tags: ,,

So this is number two in the what is new in SharePoint 2016 remote API blog series. This blog post is going to cover what is new for sharing in the remote API. In addition to some new document sharing features SharePoint 2016 has new web sharing features. Below is a screen shot of what is new in both document and web sharing. The screen shot is from the SPRemoteAPI Explorer Visual Studio extension to be released soon for SharePoint 2016.

What is new in Document Sharing?

The first thing you see is the CanMemberShare method on the SPDocumentSharingManager. This is available for CSOM,JavaScript but not REST since it takes a List as a parameter. This will return true or false if the current user has the permission to share documents for the document library. Some SharePoint hosted Add-In example code below:

function canMemberShare() {
    spHostUrl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
    context = new SP.ClientContext.get_current();
    parentContext = new SP.AppContextSite(context, spHostUrl);
    web = context.get_web();

    canShare = SP.Sharing.WebSharingManager.canMemberShare(context,web);
    
    context.executeQueryAsync(function (sender,args) {
        var c = canShare;
        alert('success');
    }, function (sender, args) {
        alert('Request failed. ' + args.get_message() +
        '\n' + args.get_stackTrace());
    });
}

Also, the SPDocumentSharingManager’s UpdateDocumentSharingInfo method has added a new argument called propagateAcl. Setting this to true appears to solve some past problems with pushing permissions down to nested AD groups and universal security groups. The response type returned on this method call also has new properties. The method will return an array of types of all the users that were given permission to a document. You now receive the display name and email of the user along with an invitation link to the document. Ths will make it easier to generate your own email messages.

Welcome to the new Web Sharing

So now we have a new SPWebSharingManager. It has similar methods as the SPDocumetSharingManager. The UpdateWebSharingInformation method can be used from CSOM and JavaScript but not REST since it takes a Web as a parameter. It has some different parameters since we are sharing a Web. It enables you to allow external sharing and like the SPDocumentSharingManager it returns an array of users that you are sharing  with along with display name, email and invitation link to possibly generate your own emails. Below is some example code from a SharePoint hosted Add-In:

function shareWebJSOM() {
    spHostUrl = decodeURIComponent(getQueryStringParameter('SPHostUrl'));
    context = new SP.ClientContext.get_current();
    parentContext = new SP.AppContextSite(context, spHostUrl);
    web = context.get_web();
    
    var userRoleAssignments = [];
    var roleAssignment = new SP.Sharing.UserRoleAssignment();

    //view only
    roleAssignment.set_role(1);
    roleAssignment.set_userId('win2012r2dev\test');
    userRoleAssignments.push(roleAssignment);

    var sharingResults = SP.Sharing.WebSharingManager.updateWebSharingInformation(context,web,userRoleAssignments,false,"Look at this web",true,false);
   
    context.executeQueryAsync(function () {
        var sharingResult = sharingResults[0];
        u = sharingResult.get_user();
        name = sharingResult.get_displayName();
        email = sharingResult.get_email();
        link = sharingResult.get_invitationLink();
    }, function (sender,args) {
        alert('Request failed. ' + args.get_message() +
        '\n' + args.get_stackTrace());
    });


}

Unfortunately, this will only work with an app web and not the host web. The server side code checks to make sure the Web that is passed as an argument is in the same web as the context. So if you want to do some bulk web sharing then powershell and CSOM would be ideal.

More ways to share in SharePoint 2016

SharePoint 2016 has added a lot to the remote API features and one is the new feature to share a Web. There is more to come in the next post.

Monday, December 14, 2015

How to make the new SharePoint Hosted Add-In deploy in SharePoint 2016 Beta 2

Technorati Tags: ,,

So I have been working with SP2016 Beta 2 and one of the complaints right now is that the Visual Studio 2015 Office Developer Tools Preview SharePoint Hosted Add-In will not deploy. So basically you need to change the target office version to 16.0 in the Visual Studio project file. The steps are illustrated below.

Create a new project:

 

Make sure to choose SharePoint Online as the target:

Choose SharePoint Hosted Add-In:

Now when you try to deploy you will get this error:

Open up the project file and change the target office version to 16.0

Deploy that SharePoint hosted Add-In to SharePoint 2016 Beta 2!

So after you change the target office version to 16.0 you will now be able to deploy to SharePoint 2016. Microsoft is currently working on fixing this in next phase of Visual Studio 2015 Office Developer Tools. In the meantime start digging in.