Caner Tosuner

Leave your code better than you found it

Sharepoint Add People Picker Control

To add people picker on your upload.aspx or any other sharepoint aspx pages;

First create a div for picker 

<div id="PeoplePickerDiv"></div>

Write your rest api functon to get people

function initializePeoplePicker(peoplePickerElementId) {

    var schema = {};
    schema['PrincipalAccountType'] = 'User,DL,SecGroup,SPGroup';
    schema['SearchPrincipalSource'] = 15;
    schema['ResolvePrincipalSource'] = 15;
    schema['AllowMultipleValues'] = true;
    schema['MaximumEntitySuggestions'] = 50;
    schema['Width'] = '280px';

    this.SPClientPeoplePicker_InitStandaloneControlWrapper(peoplePickerElementId, null, schema);
}

Initialize Your People Picker

initializePeoplePicker('PeoplePickerDiv');

Get Selected Users

var peoplePickerUserIDArray = [];
function peoplePickerGetSelectedUsersArray() {
	
    // Get the people picker object from the page.
    var peoplePicker = this.SPClientPeoplePicker.SPClientPeoplePickerDict.PeoplePickerDiv_TopSpan;


    // Get information about all users.
    var users = peoplePicker.GetAllUserInfo();

    var userInfo = '';
    for (var i = 0; i < users.length; i++) {
        var user = users[i];
        peoplePickerSetUserIdArray(user.Key);
    }
}

function peoplePickerSetUserIdArray(loginName) {

    var context = new SP.ClientContext.get_current();
    var user = context.get_web().ensureUser(loginName);
    context.load(user);
    context.executeQueryAsync(
        Function.createDelegate(null, function() {
            peoplePickerUserIDArray.push(user.get_id());
        }),
        Function.createDelegate(null, function(se, ea) {
            alert('Error:' + ea.get_message());
        })
    );
}

Sharepoint Rest Get User By

Get All Users List 

http://your-site-name/_vti_bin/ListData.svc/UserInformationList

 

Get A User By Account or Any Other Property

http://your-site-name/_vti_bin/ListData.svc/UserInformationList?$filter=Account eq ‘contoso\administrator’&$select=Id,Name

 

Get Users by Content Type

http://your-site-name/_vti_bin/ListData.svc/UserInformationList? $filter=ContentType eq ‘Person’

Sharepoint Callout Position Problem

I don't know why but I had this problem when I display Search Results. The position of the callout popup did not work what ıt was expected. 

 

To solve this problem modified "ms-wpContentDivSpace" style in core15.js has position:relative, which breaks the hover placement. Overriding that as position:inherit in custom CSS works around and solved the problem.

Sharepoint Hide Ribbon

To hide the ribbon nav bar from your html you can get use of these two ways;

First way add the below css class to your css file

#s4-ribbonrow {
    display: none;
}

 

Second way use javascript to hide it

<script type="text/javascript"> document.getElementById("s4-ribbonrow").style.display = "none"; </script>