Friday, February 9, 2018

Create Folder in SharePoint using REST

Here is the quick code snippet to create a folder in a Library or List using SharePoint REST.
var docLibraryName = "DocLibrary";
var folderName = "FolderTest";
var appWebUrl = "http://weburl";

var folderRelativePath = ''; //Populate with the path after folder creation to add files to folder
var folder = CreateFolder(appWebUrl, docLibraryName, folderName);
if (folder && folder.statusText && folder.statusText == 'Created') {
    if (folder.responseJSON && folder.responseJSON.d) {
        folderRelativePath = folder.responseJSON.d.ServerRelativeUrl;
    }
}

////Method to create a folder and returns folder object with metadata
CreateFolder = function (url, libraryname, foldername) {
    var folderRelPath = libraryname + '/' + foldername;
    var requestUri = url + "/_api/web/folders";
    var data = $.ajax({
        url: requestUri,
        type: "POST",
        async: false,
        data: JSON.stringify({ '__metadata': { 'type': 'SP.Folder' }, 'ServerRelativeUrl': folderRelPath }),
        headers: {
            "accept": "application/json; odata=verbose",
            "content-type": "application/json; odata=verbose",
            "X-RequestDigest": $("#__REQUESTDIGEST").val()
        },
        success: function (data) {
            alert('Folder created successfully.');
            return data;
        },
        error: function (error) {
            alert('Folder creation failed!');
            //alert(JSON.stringify(error));
            return data;
        }
    });
    return data;
}
Reference:
SharePoint REST Create Folder in Library
Creating Folder in Library using REST
REST Create Folder in SharePoint Library

Monday, February 5, 2018

SharePoint 2016 Email Event Receiver is Missing

Requirement:
I have a requirement to process the income emails into a SharePoint 2016 library. Thought of using SPEmailEventReceiver class and its features to process the email to capture Subject, Body and any Attachments in it.

Problem:
For some reason SPEmailEventReceiver class is not available in SharePoint 2016 project. Later came to know that it has been discontinued in SharePoint 2016 and cannot be used it.

Solution:
After doing some research, i came to know that the alternative for the same is Microsoft Flow.
I found a nice article on how it can be achieved is here.

Wednesday, January 24, 2018

ShareGate Issue Not Listing All Site Collections under a Web Application

Problem:
Sharegate is not listing down all the site collection under a web application, when connected to a web application.  Though the connection is made successfully.

Solution/Resolution:
It requires a separate connection for each site collection. So need to connect to a site collection before you use it for any reporting/migration.

Observation:
It could be a bug in Sharegate tool.

Thursday, January 18, 2018

SharePoint REST Get All Columns of a List

The below sample lists all the internal names columns of a list.
<script type="text/javascript">
$(document).ready(function () {
    console.log("ready!!");

$.ajax({
        url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('ListName')/items?$select=*",
        type: "GET",
        headers: {
            "accept": "application/json;odata=verbose",
        },
        success: function (data) {
            console.log(data.d.results);
        },
        error: function (error) {
            console.log(JSON.stringify(error));
            alert("Error occured in loading columns!");
        }
    });

});
</script>

Thursday, April 13, 2017

C# Split Comma Separated emails

private static string FormatMultipleEmailAddresses(string emailAddresses)
{
var delimiters = new[] { ',', ';' };

var addresses = emailAddresses.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

return string.Join(",", addresses);
}