Interview Questions administrator

Best SharePoint administrator Interview Questions and Answers with topic wise:


Recycle Bin | MMS | ManagedVsCrawledProperties |
Showing posts with label apps. Show all posts
Showing posts with label apps. Show all posts

Monday, December 26, 2016

Get sharepoint Host Web Url using REST

Just do copy paste the below code and execute it.


Note: The below shared code is 100% verified/executed.


Appmanifest.xml:

Set read level permisisons to the web

Default.aspx:

The host web title is: <label id="HostwebTitle"></label>

app.js:

var hostweburl;
var appweburl;

// Load the required SharePoint libraries
$(document).ready(function () {
    appweburl = window.location.protocol + "//" + window.location.host + _spPageContextInfo.webServerRelativeUrl;
    hostweburl = _spPageContextInfo.siteAbsoluteUrl;

    // resources are in URLs in the form:
    // web_url/_layouts/15/resource
    var scriptbase = hostweburl + "/_layouts/15/";

    // Load the js file and continue to the
    //   success event handler
    //$.getScript(scriptbase + "SP.RequestExecutor.js", execCrossDomainRequest);
    $.getScript(scriptbase + "SP.js", execCrossDomainRequest);
});

// Function to prepare and issue the request to get
//  SharePoint data
function execCrossDomainRequest() {
    var executor;

    // Initialize the RequestExecutor with the app web URL.
    executor = new SP.RequestExecutor(appweburl);

    // Issue the call against the host web.
    // To get the title using REST we can hit the endpoint:
    //      app_web_url/_api/SP.AppContextSite(@target)/web/title?@target='siteUrl'
    // The response formats the data in the JSON format.
    // The functions successHandler and errorHandler attend the
    //      success and error events respectively.
    executor.executeAsync(
        {
            url:
                appweburl +
                "/_api/SP.AppContextSite(@target)/web/title?@target='" +
                hostweburl + "'",
            method: "GET",
            headers: { "Accept": "application/json; odata=verbose" },
            success: successHandler,
            error: errorHandler
        }
    );
}

// Function to handle the success event.
// Prints the host web's title to the page.
function successHandler(data) {
    var jsonObject = JSON.parse(data.body);


    document.getElementById("HostwebTitle").innerHTML =
        "<b>" + jsonObject.d.Title + "</b>";
}

// Function to handle the error event.
// Prints the error message to the page.
function errorHandler(data, errorCode, errorMessage) {
    document.getElementById("HostwebTitle").innerText =
        "Could not complete cross-domain call: " + errorMessage;
}

// Function to retrieve a query string value.
// For production purposes you may want to use
//  a library to handle the query string.
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];
    }
}

Thanks for visting.. Happy Sharepoint

Please take a moment and do comments on it if its really helped you.

Tuesday, November 25, 2014

Create sharepoint site in Office365 using powershell script

Just do copy/paste the below script in you powershell and see the magic..You will be able to new site in your office 365 application.

Am sharing the below script to all of my SharePoint colleges once did the experiments from my side.

*********************************************************************************
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("User-Agent","Mozilla/4.0+")      
$wc.Proxy = [System.Net.WebRequest]::DefaultWebProxy
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
Add-Type –Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type –Path "C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type –Path "C:\Program Files\SharePoint Client Components\16.0\Assemblies\Microsoft.Online.SharePoint.Client.Tenant.dll"
$siteUrl = “http://xxx.xxxx.com”
$password = convertto-securestring "*****" -asplaintext -force
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($siteUrl)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials("username", $password)
$ctx.Credentials = $credentials
$webCreationInformation = New-Object Microsoft.SharePoint.Client.WebCreationInformation
$webCreationInformation.Url = "URLName"
$webCreationInformation.Title = "Title"
$webCreationInformation.WebTemplate = "STS#0"
$newWeb = $ctx.Web.Webs.Add($webCreationInformation)
$ctx.Load($newWeb)
$ctx.ExecuteQuery()
**********************************************************************************
Please let me know for any concerns.

-Thanks,
Sasi Kumar Reddy
https://sharepointquicksolutions.blogspot.com

Tuesday, July 15, 2014

Minimal master page in SharePoint 2013:

Step1: Select “Design Manager” and click on “Edit Master pages

 
Step2: Select “Create a minimal master page” and enter the minimal master page name “SampleMinimal” and click on “Ok” button.

 Step3: Open the minimal master page through SharePoint designer 2013 and add the below lines of code in “SampleMinimal.html”
Reason: “Design Manager” Bug in SharePoint 2013:
The actual issue is users are unable to create list/library after applying the minimal master page.
But when we are trying to create a new Document-library or List using "add an app" link it always shows "loading...” as shown in image and never ends.
<div style="display: none;">
<!--SPM:<SharePoint:AjaxDelta id="DeltaPlaceHolderLeftNavBar" BlockElement="true" runat="server">-->
<!--SPM:<asp:ContentPlaceHolder id="PlaceHolderLeftNavBar" runat="server">-->
<!--SPM:</asp:ContentPlaceHolder>-->
<!--SPM:</SharePoint:AjaxDelta>-->
<!--SPM:<SharePoint:AjaxDelta id="DeltaPlaceHolderPageTitleInTitleArea" runat="server">-->
<!--SPM:<asp:ContentPlaceHolder id="PlaceHolderPageTitleInTitleArea" runat="server">-->
<!--SPM:</asp:ContentPlaceHolder>-->
<!--SPM:</SharePoint:AjaxDelta>-->
</div>
 

Step4: Publish the major of version to the “SampleMinimal” minimal master page.
Step5: Set this minimal master page as default master to the site.

Please let me know if faced any issues.

Sunday, May 5, 2013

Add Button to sharepoint Ribbon control using visual studio 2012

In this task, you will add a custom action to the ribbon of all Document Libraries to launch the App.
  1. In Visual Studio, right click the HelloApp node and select AddØNew Item from the Context menu.
  2. In the New Item dialog, select Ribbon Custom Action.
  3. Name the item Launcher and click Add.

Saturday, May 4, 2013

Create Client Web Part to the App using visual studio 2012

In this task, you will add a Client Web Part and code it. This web part can be used on pages outside of the App to add functionality to the hosting SharePoint site.
  • Add a Client Web Part
    • In the Solution Explorer, right click the HelloApp project node and select Add-->New Item from the context menu.
    • In the Add New Item dialog, select Client Web Part.
    • Name the new item MyClientWebPart and click Add.

Wednesday, January 23, 2013

List Operations on Sharepoint Apps: using ECMAScript

Below content will help to guide you on below things:
  1. How to get the host web url? 
  2. How to check whether the list exists or not? 
  3. How to create a list? 
  4. How to create fields? 
  5. How to add Items into the list? 
  6. How to Read items from the list?
Just replace the below code with your "app.js" file on office365(Napa tool) and see the magic.  Please give the required permission levels to do CRUD operations on the hosted site like read/write permissions otherwise get access denied error.

Thursday, January 17, 2013

Access denied on: Napa tool/ SharePoint 2013 apps


Recently I got the "Access Denied" issue when I try to access the lists data from the Visual Studio 2012 apps and Napa tool.

To get the access permissions from the Napa tool:
You will get the below popup up window once you clicked on "properties" tab[see below fig] and here you can give the access according to your functionality.

Check whether the list exists or not using ECMAScript

In SharePoint 2013 when you create any SharePoint Hosted App it will create separate web for the app you created. You can find it easily by verifying the URL at the browser.
1) SPHostUrl 2) SPAppWebUrl

Thursday, January 10, 2013

Get Host Web Url in SharePoint 2013/Office365 apps using JSOM

Get HostWeb URL through JavaScript object model:

Just do copy/paste the below code and execute it.



Note: The below shared code is 100% verified/executed.

Please reach the below post URL to get the hostweb url through REST service
http://sharepointquicksolutions.blogspot.com/2016/12/get-sharepoint-host-web-url-using-rest.html 

Appmanifest.xml:

Set read level permisisons to the web

Default.aspx:

<p id="getHostWebURL"> </p>

App.js

'use strict';
var hostweburl, appweburl;
var website;

$(document).ready(function () {
    appweburl = window.location.protocol + "//" + window.location.host + _spPageContextInfo.webServerRelativeUrl;
    hostweburl = _spPageContextInfo.siteAbsoluteUrl;

    //hostweburl = decodeURIComponent(getQueryStringParameter("SPHostUrl"));
    //appweburl = decodeURIComponent(getQueryStringParameter("SPAppWebUrl"));
    var scriptbase = hostweburl + "/_layouts/15/";

    $.getScript(scriptbase + "SP.Runtime.js",
        function () {
            $.getScript(scriptbase + "SP.js", retrieveListItems);
        }
    );
});

// Function to retrieve a query string value.
// For production purposes you may want to use
// a library to handle the query string.
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];
    }
}

function retrieveListItems() {
    var context = new SP.ClientContext(appweburl);
    var appContextSite = new SP.AppContextSite(context, hostweburl);
    website = appContextSite.get_web();
    context.load(website);
    context.executeQueryAsync(onGetWebSuccess, onGetWebFail);

    //the remaining code is omitted for clarity  
}

function onGetWebSuccess() {
    alert("calling" + website.get_title());
    $('#getHostWebURL').text("The title of the host web of this app is " + website.get_title());
}

function onGetWebFail(sender, args) {
    alert('Failed to get lists. Error:' + args.get_message());
}

How to: Create fields in sharepoint list using ECMAScript

By using below code we can create fields of different types using ECMAScript:
function createFields()
{
   currentcontext = new SP.ClientContext.get_current();
   web = clientContext.get_web();
   this.list = web.get_lists().getByTitle(‘ListName’);  
 //Add new fields to the list

//Single line of text Field
this.newColumn = oList.get_fields().addFieldAsXml("", true,
    SP.AddFieldOptions.defaultValue);
 
//Multi line of text Field
this.newColumn = oList.get_fields().addFieldAsXml("", true,
    SP.AddFieldOptions.defaultValue);
 
//Boolean Field
this.newColumn = oList.get_fields().addFieldAsXml("", true,
    SP.AddFieldOptions.defaultValue);

//Number Field
this.newColumn = oList.get_fields().addFieldAsXml("", true,
    SP.AddFieldOptions.defaultValue);

//DateTime Field
this.newColumn = oList.get_fields().addFieldAsXml("", true,
  SP.AddFieldOptions.defaultValue);

//People Picker Field
this.newColumn = oList.get_fields().addFieldAsXml("", true,
  SP.AddFieldOptions.defaultValue);

//Choice field(dropdown)
 this.newColumn= oList.get_fields().addFieldAsXml("ChoiceAChoiceAChoiceBChoiceCChoiceD", true, 
  SP.AddFieldOptions.defaultValue);
 
 currentcontext.load(this.newfield);
 currentcontext.executeQueryAsync(Function.createDelegate(this, this.onListCreateSuccess), Function.createDelegate(this, this.onQueryFailed));
}

function onListCreateSuccess(sender, args) {alert('sucess');
    alert("Field Name: " + this.newfield.get_title());
}
 
function onQueryFailed(sender, args) {
 alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}
Note: SP.Field.typeAsString Property is used to Gets or sets a value that specifies the type of the field.[From Msdn:http://msdn.microsoft.com/en-us/library/ee553500.aspx]

Wednesday, January 2, 2013

Error occurred in deployment step 'Uninstall app for SharePoint":

I am facing the below issues regularly while deploying the SharePoint hosted apps to both either office 365 sites or SharePoint sites from the visual studio. So guys, please help me on it.

 Error occurred in deployment step 'Uninstall app for SharePoint': Only users who can View Pages can list Apps.
Error occurred in deployment step 'Uninstall app for SharePoint': The underlying connection was closed: An unexpected error occurred on a receive.
Error occurred in deployment step 'Uninstall app for SharePoint': The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.
Error occurred in deployment step 'Uninstall app for SharePoint': Communication with the SharePoint server is canceled.

Tuesday, December 18, 2012

App web Vs Host Web

The special website to which the app is deployed is called an app web. The website to which the app is installed is called the host web. Although the app web has its own isolated domain, it is in the same site collection as the host web.
SharePoint components are deployed to a special website with its own domain. This is called the app web.

SharePoint hosted vs Cloud hosted apps


Difference between SharePoint hosted apps and cloud hosted apps?
An app for SharePoint can have both SharePoint-hosted and cloud-hosted components. The app does not (actually cannot) contain custom code that executes on the SharePoint servers, administrators are assured of its safety.

Cloud hosted:  
  1. This type of hosting is used when app has at least one remote component. It may also include SharePoint hosted components. There are two types in Cloud hosted apps.
  2. The external components [also called Remote components] are persisted in databases, servers, or cloud-based services that are external to the SharePoint farm.
  3. Cloud-Hosted Apps are also referred to as server-side apps.
  4. Cloud-Hosted SharePoint 2013 Apps include components hosted outside your SharePoint farm. Such components can be hosted on IIS servers, Apache servers, or cloud services such as Windows Azure.
  5. When it is required exactly is if we require server-side components in apps. In such situations, you must write a Cloud-Hosted App. Also known as server-side apps.

Simply way to get an idea on SharePoint 2013 apps

Apps in SharePoint 2013:
An app for SharePoint is a web application that is registered with SharePoint using an app manifest and  An app manifest is an XML file that declares the basic properties of the app along with where the app will run and what to do when the app is started.

App Model: The new app model will give us the opportunity to extend our SharePoint system with custom coding. Earlier models support Sandbox solutions and in 2013 we have both Sandbox and App models. 

List item count is zero in SharePoint apps:


If you are getting the count as zero even the data exists means that you don’t have item level permissions. Please follow up the below steps to give permissions at the list item levels in apps.




Another way to add permissions:
Just right click on “Appmanifest.xml”, select “view code” and then add the below code in it.