Access Denied on use of AppPrincipalManager

We are getting the following error

Access denied. You do not have permission to perform this action or access this resource.

when executing the following code

AppPrincipalManager ap = AppPrincipalManager.GetManager(web.Context, web);

I get it with every account: my account (site collection admin), system account, …
It just doesn’t work.

We need it because we want to add apps on a site by CSOM. That works, but the app permissions are not set. So we are trying to set them by the AppPrincipalManager. But then, we get an access denied error.

SharePoint 2013 Online Search Query for Site Collections

I wonder if It’s possible to get all my site collection names or paths in Javascript, Visual Studios. I’ve found them through REST when I put
in the adressbar in Internet Explorer. I’m using SharePoint Online in Office 365. But how do I do it code wise in Javascript. I’ve tried some examples but none have worked.

Thanks in advance!

Add Webparts through SharePoint hosted app

I am trying to add a webpart trough and app. I have provisioned some files in different extensions sucessfully.

The last step for my app is to add a content editor web part on the hostweb welcome page, now it says undefined. Heres my code:

"use strict";
//Provision Web Part on Host Web
var hostweb;
var hosturl;

function getRelativeUrlFromAbsolute(absoluteUrl) {
absoluteUrl = absoluteUrl.replace('https://', '');
var parts = absoluteUrl.split('/');
var relativeUrl = '/';
for (var i = 1; i < parts.length; i++) {

    relativeUrl += parts[i] + '/';
return relativeUrl;

function getQueryStringParameter(param) {
var params = document.URL.split("?")[1].split("&");
for (var i = 0; i < params.length; i = i + 1) {
    var singleParam = params[i].split("=");
    if (singleParam[0] == param) {
        return singleParam[1];

function addWebPart() {

var hostUrl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
var currentcontext = new SP.ClientContext.get_current();
var hostcontext = new SP.AppContextSite(currentcontext, hostUrl);
var hostweb = hostcontext.get_web();

//add a content editor web part to the default.aspx page
var pageToAddWP = hostweb.getFileByServerRelativeUrl(hostUrl +    "SitePages/DevHome.aspx");

//get out webpartmanager object for imports
var limitedWebPartManager = pageToAddWP.getLimitedWebPartManager(SP.WebParts.PersonalizationScope.shared);

var webPartXml = '<?xml version="1.0" encoding="utf-8"?>' +
    '<WebPart xmlns:xsi=""' + 
    ' xmlns:xsd=""' + 
    ' xmlns="">' + 
    '<Title>My Web Part</Title><FrameType>Default</FrameType>' + 
    '<Description>Use for formatted text, tables, and images.</Description>' + 
    '<IsIncluded>true</IsIncluded><ZoneID></ZoneID><PartOrder>0</PartOrder>' + 
    '<FrameState>Normal</FrameState><Height /><Width /><AllowRemove>true</AllowRemove>' + 
    '<AllowZoneChange>true</AllowZoneChange><AllowMinimize>true</AllowMinimize>' + 
    '<AllowConnect>true</AllowConnect><AllowEdit>true</AllowEdit>' + 
    '<AllowHide>true</AllowHide><IsVisible>true</IsVisible><DetailLink /><HelpLink />' + 
    '<HelpMode>Modeless</HelpMode><Dir>Default</Dir><PartImageSmall />' + 
    '<MissingAssembly>Cannot import this Web Part.</MissingAssembly>' + 
    '<PartImageLarge>/_layouts/images/mscontl.gif</PartImageLarge><IsIncludedFilter />' + 
    '<Assembly>Microsoft.SharePoint, Version=, Culture=neutral, ' + 
    'PublicKeyToken=94de0004b6e3fcc5</Assembly>' + 
    '<TypeName>Microsoft.SharePoint.WebPartPages.ContentEditorWebPart</TypeName>' + 
    '<ContentLink xmlns="" />' + 
    '<Content xmlns="">' + 
    '<![CDATA[This is a first paragraph!<DIV>&nbsp;</DIV>And this is a second paragraph.]]></Content>' + 
    '<PartStorage xmlns="" /></WebPart>';

var webPartDefinition = limitedWebPartManager.importWebPart(webPartXml);
var webpart = webPartDefinition.get_webPart();

limitedWebPartManager.addWebPart(webpart, "Left", 1);

currentcontext.executeQueryAsync(onAddWPSuccess, onAddWPFailed);
function onAddWPSuccess() {

 $('#message').append('<br /><div>WebPart succesfully added!</div>');
  function onAddWPFailed(sender, args){

$('#message').append('<br />Failed to provision webpart into host web. Error:' +   sender.statusCode);

Error starting a workflow on host web from within a SharePoint-hosted app

I am trying to start a workflow on the host web from within a web part in an app. Here is my code:

var clientContext = new SP.ClientContext.get_current();
var hostWebUrl = hostUrl;
var hostWebContext = new SP.AppContextSite(clientContext, hostWebUrl);

var wfServiceManager = SP.WorkflowServices.WorkflowServicesManager.newObject(clientContext, hostWebContext.get_web());

var subscription = wfServiceManager.getWorkflowSubscriptionService().getSubscription(subId);

clientContext.executeQueryAsync(function() {
    console.log("Subscription " + subscription.get_name() + " was loaded, attempting to start workflow.");
    var inputParameters = { };

    wfServiceManager.getWorkflowInstanceService().startWorkflowOnListItem(subscription, itemId, inputParameters);

    clientContext.executeQueryAsync(function() {
        console.log("Successfully started workflow.");
    }, function(sender, args) {
        console.log("Failed to start the workflow.");
        console.log("Error: " + args.get_message() + "n" + args.get_stackTrace());
}, function(sender, args) {
    console.log("Failed to load the subscription.");
    console.log("Error: " + args.get_message() + "n" + args.get_stackTrace());

I get an error at the wfServiceManager.getWorkflowInstanceService().startWorkflowOnListItem(subscription, itemId, inputParameters); line, with the following shown in the console:

Subscription My Test Workflow for the App was loaded, attempting to start workflow.
Failed to start the workflow.
Error: Value cannot be null.
Parameter name: input

Does anyone have any idea what is wrong? My workflow is a simple workflow, it just updates a field; no input form.

Getting formatted HTML out of SharePoint wiki library

In our application, we are using SharePoint wiki library loosely as a content management system. Through custom code, I retrieve the contents of the wiki library along with its properties.

        var array = new List<object>();
        MsOnlineClaimsHelper claimsHelper = new MsOnlineClaimsHelper("", "myusername", "mypassword");
        using (ClientContext context = new ClientContext("mylocation"))
            context.ExecutingWebRequest += claimsHelper.clientContext_ExecutingWebRequest;
            Web web = context.Web;
            ListCollection lists = web.Lists;
            List selectedList = lists.GetByTitle("mylistname");
            CamlQuery query = CamlQuery.CreateAllItemsQuery();
            ListItemCollection items = selectedList.GetItems(query);
            foreach (ListItem listItem in items)
                    sharepointid = listItem["ID"].ToString(),
                    wikicontent = Convert.ToString(listItem["WikiField"] as object),
        return array;

The wikicontent comes back with the HTML, problem is, it doesnt have all of the style information associated with it. So the HTML does not look like how it looks in the wiki.

Content in Wiki

Wiki Content

Content from retrieved HTML

Content from retrieved HTML

The actual HTML that I get from the code above looks like

<div class="ExternalClass7A473DBC7A6C41109A4FC8978BF5BDD9">
<table id="layoutsTable" style="width:100%;">
         <tr style="vertical-align:top;">
            <td style="width:100%;">
               <div class="ms-rte-layoutszone-outer" style="width:100%;">
                  <div class="ms-rte-layoutszone-inner" role="textbox" aria-autocomplete="both" aria-haspopup="true" aria-multiline="true">
                     <h1>​​​This is a test page<br></h1>
                     <p>... and <span class="ms-rteFontSize-3">this </span>is a test <span class="ms-rteFontSize-6">content</span>, that has been <span class="ms-rteFontFace-7">formatted</span>. <br></p>
   <span id="layoutsData" style="display:none;">false,false,1</span>

How do I get the proper formatting information?

High-trust provider-hosted app vs. standalone web application with CSOM

I’m considering developing a website based on MVC, with SharePoint 2013 in the background – used for document management, permissions and workflows. I’m not interested in providing any SharePoint interface functionality (such as webparts, ribbon, list item menu etc.) to the users. Basically, the users will only interact with the MVC web application.

Both the MVC application and SharePoint would be using FBA, with the same DB.

I’m trying to get a clear list of pros and cons for using the app model in order to achieve this.

I know that app permissions are one thing to consider, because of the possibility of making requests by using the app permissions instead of the permissions of the current user.

With or without an app, the MVC website would still be using CSOM.

So, anyone might shed some more light upon the reasons for using the app model, with the overhead that it produces?

SharePoint 2013 – AppStore with Anonymous Authentication

I want to use the SharePoint 2013 App Store with SharePoint hosted apps and anonymous authentication.

My SharePoint works fine excpt the anonymous access to SharePoint sites with apps.

Is there there a configuration guide to use app with anonymous access?

Any ideas how I can fix this problem?

Entering monitored scope (SPClaimsCounterScope). Parent Request
Value for isAnonymousAllowed is : True Value for
checkAuthenticationCookie is : True Looking up context site
in the farm SharePoint_Config Site lookup found the host header site
GetSchemeHostHeaderZoneForSiteCreation has been called in the app
context for a non Host Header site. Returning data using the response
url. SPFederationAuthenticationModule.OnEndRequest: User was being
redirected to authenticate. Claims Windows Sign-In: Sending 401 for
because the user is not authenticated and resource requires

Show status bar in created site from a Sharepoint Hosted App

I am creating a custom site from a Sharepoint Hosted App.

You know It´s posible to add a status bar in the site when is showing for the first time after redirect from a sharepoint app?

Need to auto-populate a list column with a sequential number in 2013

We’ve come up with our equation to generate job numbers that would show, as example for now, ROV-141 but we want leading zeros between the year and new number, i.e. ROV-1400001 or ROV-1403099. we always want 5 digits after the year & thus that number could be 00001 and all the way up to 09999. how do we modify end of following equation to allow for leading zeros in Sharepoint 2013? no coding please – we don’t have a programmer on staff yet, nor do i have access. the equation below works to extent, but not to where we want it to be.


Consume WCF REST service in SharePoint Hosted App

How to consume the WCF REST service in a SHarePoint Hosted App? Please give me some examples through CuRD operation

Question and Answer is proudly powered by WordPress.
Theme "The Fundamentals of Graphic Design" by Arjuna
Icons by FamFamFam