Thursday, November 20, 2014

We apologize for any inconvenience, but we've made the site read only while we're making some improvements

image

This message shows when I accidentally close my backup script of the SharePoint site. This massage is prompted by the SharePoint when  a site is in a maintenance mode.

Resolutions

Method 1

image

  1. Go to the central administrator
  2. Application management –> Site Collection Quotas and Locks
  3. Select the site collection and change the locks information to Not Locked.

Some times this page looks like disabled thus you need to try the method two.

Method 2

$Admin = new-object Microsoft.SharePoint.Administration.SPSiteAdministration('https://www.site/sites/sitecollection')
$Admin.ClearMaintenanceMode()

This PowerShell Script changes the site collection back to normal.

Tuesday, November 11, 2014

How to initialize the SharePoint Client Context in SharePoint Apps (Provider Hosted / SharePoint Hosted) using JSOM (JavaScript Object Model)

 

SharePoint Provider Hosted Apps

First of all we need to understand the SharePoint Provider Hosted hosting blocks.

image

Provider hosted involves two hosting domains (ex host, sphost). thus request sending to host to sphost considering as cross domain request.

For cross domain request we need to provide SPAppWebUrl to initialize the context. SPAppWebUrl  is available in Url.

Ex:-

https://host.azurewebsites.net/pages/default.aspx?SPHostUrl=https:%2F%2Fsphost.sharepoint.com%2Fsites%2app&SPLanguage=en-US&SPClientTag=0&SPProductNumber=16.0.3417.1223&SPAppWebUrl=https:%2F%2Fsphost-265535272e9c8d.sharepoint.com%2Fsites%2Fapp%2FSample&Source=https://app.azurewebsites.net/pages/default

we can get AppWebUrl by accessing Url parameter. following shows a utility function for getting Url parameter.

function getQueryStringParameter (paramToRetrieve) = {
    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] == paramToRetrieve)
            return singleParam[1];
    }
    return "";
};

This will initiate the client context using remote web Url.



var spAppWebUrl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
var ctx = new SP.ClientContext(spAppWebUrl);
var factory = new SP.ProxyWebRequestExecutorFactory(spAppWebUrl);
ctx.set_webRequestExecutorFactory(factory);
var web = ctx.get_web();
 
ctx.executeQueryAsync(
    function () {
           alert("sucess"); },
    function (a, b) {
           alert("error");  }
);

 


SharePoint Hosted Apps


SharePoint Hosted app does not have separate hosting server. SharePoint hosted apps run on the same SharePoint server. thus client context initialization does not need to provide the Url.



var ctx = new SP.ClientContext.get_current();
var web = _sa.ctx.get_web();
ctx.executeQueryAsync(
    function () {
           alert("sucess"); },
    function (a, b) {
           alert("error");  }
);

Tuesday, October 28, 2014

Working with SharePoint folder properties using CSOM (Client Side Object model ) in SharePoint 2013

 

Accessing folder properties are but different from  SharePoint list item access. Following code demonstrates  the basics.

Create SharePoint Folder with Properties

using (var clientContext = ypurMethodToGetSpContectt() )
{
 
    var lst = clientContext.Web.Lists.GetByTitle("ListName");
    var folder = lst.RootFolder.Folders.Add("FolderName");
    
    folder.Properties["property1"] = "sample";
    folder.Properties["property1"] = "sample";
 
    folder.Update();
    clientContext.ExecuteQuery();
 
}

Tuesday, September 30, 2014

How to add/update SharePoint user field (person group column) using ECMA Scripts

 

SharePoint app model supports enough capability to work with SharePoint from JavaScript.

Working with Person Group column is a common task in SharePoint development. Following illustrates how to  update  a single and multiple values to  SharePoint person group column.

Insert / Update Single Value SharePoint Person Group Column (People Field)

Tip: For single value you should refer the person or group by ID

var  user = new SP.FieldUserValue();
user = 1; // this is the ID for User or Group in SharePoint
 
listitem.set_item("Column Name", user);
listitem.Update();
ctx.ExecuteQuery();

Insert / Update Multi Value SharePoint Person Group Column (People Field)


Tip: For multiple users you need to refer it by login name



var  users =[];
 
users.push(SP.FieldUserValue.fromUser("dev Members")); // adding group
users.push(SP.FieldUserValue.fromUser("i:0#.f|membership|melick@oapp.onmicrosoft.com")); // adding user
 
 
listitem.set_item("Column Name", users);
listitem.Update();
ctx.ExecuteQuery();


*listitem  this is the list item you need to manipulate. If you are inserting a item this will be created using ListItemCreationInfo and if you are updating a item this will be a reference to the item you seek


Ref: http://msdn.microsoft.com/en-us/library/office/hh185011(v=office.14).aspx