SharePoint Tips

Tuesday, June 26, 2018

Office 365 : Add new user


In this article, we will see how to create a new user in Office 365.

Step 1- Go to Office 365 Admin center. Open Active Users page as shown below.


Step 2- Provide the mandatory fields like Display name, Username and other optional details as per your requirement.


Step 3- For password, default option is Auto generated password but you can also provide password as shown below. You can also specify whether user needs to change password on first login on not.


Step 4- You can also specify Roles as shown in below image. Default is User (no admin access).


Step 5- Apart from Global administrator you can provide customized admin roles to user as shown in below image.


Step 6- You can also specify what kind of license you need to provide to user. Click on Add button to create user.




Step 7- Once user is created, you can send password in email as shown below.



Step 8- Now your new user is visible in active users list.



Step by step guide to create Provider hosted Add-in : SharePoint online : Office 365 : Azure

In this article we will see how to create SharePoint provider hosted Add-in
Step 1- Open Visual Studio. Create new project of type ‘SharePoint Add-in’ as shown below.


Step 2- After entering Office 365 credentials, select SharePoint online version as shown below.


Step 3- Select ASP.NET MVC web application as shown below.

Step 4- Select Azure Access Control Service for authentication as shown below.

Step 5- Now your solution with SharePoint Add-in and ASP.NET application is created as shown below.

Step 6- Publish ASP.NET web application to Azure.

Step 7- Click on Start button under Publish as shown below.

Step 8- Select App Service, Create New.

Step 9- If you are not already logged in to your Azure account then you need to login to your azure account. Now all fields as show below will be auto populated. Click of Create button. It will publish your ASP.NET application in azure.

Step 10- Once your application is published to azure it will open it will open new web app in browser with error as shown below. Now copy the url this web app for further configuration. We will use it to register add-in.

Register the Add-in in SharePoint Online
Step 11- Open add-in registration page for your SharePoint online site and generate client id and client secret as shown below. Provide all other details as shown below. In Redirect url, add https in place of http for your azure web app.
Step 12- Copy all the details of app identifier to notepad for future use.


Setup Azure Web Site’s App Settings
Step 13- Go to Application settings of your Azure web app which we created earlier. Click on ‘Add new setting’ under Application settings as show below and add settings for ClientId and ClientSecret.
Step 14- Now you have settings in your azure web app for client id and client secret. Click on Save button to save it.


Step 15- Edit AppManifest.xml file in SharePoint add-in and change start page to url of your azure web app (with https) and client id to client id we generated earlier.

Step 16- Now publish you add-in to SharePoint.


Step 17- You will see yellow alert message as shown below. Click on Edit button.


Step 18- Add client id and client secret values in it and click Finish.


Step 19- Package Add-In by clicking on Package the add-in button. In URL change http to https. Click on Finish button to create package.


Step 20-  Package is created on your local system.


Step 21- Now upload package to your app catalog.


Step 22- Go to site contents to see your provider host add-in


Step 23- Click on your add-in, it will go to the app redirect page and it will be navigated to the remote Azure Web app.


As you can see in the Browser address bar, the redirection has been completed and Azure Web app has come up in the Browser. Here, we can see the current logged in user name, which was fetched, using controller and was displayed in the view of the MVC project. We can add more logic to MVC project, as per the requirement. 

Monday, June 25, 2018

Step by step guide to create Azure Virtual Machine : Windows VM with Visual Studio


Here we will see how to create Azure virtual machine having Visual Studio 2017 on Windows.
Step 1- Login to you azure portal and click on Virtual machines link in left navigation. Click Add button.


Step 2- Click Add and search ‘visual studio’. Select the version you want from the list as shown below.


Step 3- I have selected Visual Studio Community 2017 on Windows Server 2016


Step 4- Select VM and click on Create button as shown below.


Step 5- Provide the required information.


Step 6 – Chose size for you VM. You can change size later also.


Step 7- Complete all configuration. On Summary page, you can see summary of your VM. Now click on ‘Create’ button to create your VM. It will start creation of your new VM. You have to wait for sometime till your VM gets created.


Step 8- Once your VM is created, you can see your VM from Virtual Machines link in left navigation. Now, configure Remote Desktop connection to connect your VM from your local machine.


Step 9- Configure DNS Name. This is optional. You can access you VM using IP address also.




Step 10- Now connect to your newly created virtual machine. Enter user credentials which you created during VM creation.


Now your VM is connected.



Sunday, June 24, 2018

Deploy SharePoint Add-In as App Part


In previous post ‘SharePoint hosted Add-In : Read list data : JSOM’, we saw how to create SharePoint hosted Add-In to read data from SharePoint. In this post, we will see how to deploy SharePoint Add-In as App Part. So that, this Add-In can be added to any page in SharePoint.
Step 1- Add new Client Web Part to your Add -In project.


Step 2- Create a new page or you can also use existing Default.aspx page of Add-In for client web part content.


Step 3- Create a blog subsite ‘Vendor’. In App part, we will read data from this blog posts.


Step 4- Open Client web part Element.xml file and update Title and Description.


Step 5- Deploy your Add-In


Step 6- Add your App Part from Apps category as shown below.


Step 7- Now you can see your Add-In as App part in your SharePoint sites page.


Code of App Part
<%@ Page language="C#" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<WebPartPages:AllowFraming ID="AllowFraming" runat="server" />

<html>
<head>
    <title></title>

    <script type="text/javascript" src="../Scripts/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="/_layouts/15/MicrosoftAjax.js"></script>
    <script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
    <script type="text/javascript" src="/_layouts/15/sp.js"></script>

    <script type="text/javascript">
        // Set the style of the client web part page to be consistent with the host web.
        (function () {
            'use strict';

            var hostUrl = '';
            var link = document.createElement('link');
            link.setAttribute('rel', 'stylesheet');
            if (document.URL.indexOf('?') != -1) {
                var params = document.URL.split('?')[1].split('&');
                for (var i = 0; i < params.length; i++) {
                    var p = decodeURIComponent(params[i]);
                    if (/^SPHostUrl=/i.test(p)) {
                        hostUrl = p.split('=')[1];
                        link.setAttribute('href', hostUrl + '/_layouts/15/defaultcss.ashx');
                        break;
                    }
                }
            }
            if (hostUrl == '') {
                link.setAttribute('href', '/_layouts/15/1033/styles/themable/corev15.css');
            }
            document.head.appendChild(link);
        })();
    </script>

   
    <script type="text/javascript">
        var hostweburl;
        var appweburl;
        // Load the required SharePoint libraries
        $(document).ready(function () {
            //Get the URI decoded URLs.
            hostweburl =
                decodeURIComponent(
                    getQueryStringParameter("SPHostUrl")
            );
            appweburl =
                decodeURIComponent(
                    getQueryStringParameter("SPAppWebUrl")
            );
            // resources are in URLs in the form:
            // web_url/_layouts/15/resource
            var scriptbase = hostweburl + "/_layouts/15/";
            // Load the js files and continue to the successHandler
            $.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest);
        });
        // Function to prepare and issue the request to get
        //  SharePoint data
        function execCrossDomainRequest() {
            // executor: The RequestExecutor object
            // Initialize the RequestExecutor with the app web URL.
            var executor = new SP.RequestExecutor(appweburl);
            // Issue the call against the app web.
            // To get the title using REST we can hit the endpoint:
            //      appweburl/_api/web/lists/getbytitle('listname')/items
            // The response formats the data in the JSON format.
            // The functions successHandler and errorHandler attend the
            //      sucess and error events respectively.
            executor.executeAsync(
                {
                    url: appweburl + "/_api/SP.AppContextSite(@target)/web/lists/getbytitle('Posts')/items?@target='" + hostweburl + "/Vendor'&$top=3",
                    method: "GET",
                    headers: { "Accept": "application/json; odata=verbose" },
                    success: successHandler,
                    error: errorHandler
                }
            );
        }
        // Function to handle the success event.
        // Prints the data to the page.
        function successHandler(data) {
            var jsonObject = JSON.parse(data.body);
            var blogsHTML = "";
            var results = jsonObject.d.results;
            for (var i = 0; i < results.length; i++) {
                blogsHTML = blogsHTML + "<div><a href=\"" + hostweburl + "/Vendor/Lists/Posts/Post.aspx?ID=" + results[i].ID + "\" target=\"_blank\">" + results[i].Title + "</a></div><br>";
            }
            $('#myDiv').append(blogsHTML);
        }
        // Function to handle the error event.
        // Prints the error message to the page.
        function errorHandler(data, errorCode, errorMessage) {
            document.getElementById("myDiv").innerText =
                "Could not complete cross-domain call: " + errorMessage;
        }
        // Function to retrieve a query string value.       
        function getQueryStringParameter(paramToRetrieve) {
            var params =
                document.URL.split("?")[1].split("&");
            var strParams = "";
            for (var i = 0; i < params.length; i = i + 1) {
                var singleParam = params[i].split("=");
                if (singleParam[0] == paramToRetrieve)
                    return singleParam[1];
            }
        }
    </script>

</head>
<body>
    <div>
        <div><strong> Vendors</strong></div>
        <div id="myDiv"></div>
       
    </div>
</body>
</html>