Loading...

Tuesday, May 14, 2013

How To Identify If SharePoint App is installed on On-Premise or In Cloud?


This can be determined by Context Token as follows

protected void Page_Load(object sender, EventArgs e)
{
  Uri hostWeb = new Uri(Request.QueryString["SPHostUrl"]);
  string contextTokenString =
    TokenHelper.GetContextTokenFromRequest(Request);

  if (string.IsNullOrEmpty(contextTokenString))
  {
    // if On-Prem
    using (var clientContext = TokenHelper.GetS2SClientContextWithWindowsIdentity(
      hostWeb,
      Request.LogonUserIdentity))
    {
      . . .
    }
  }
  else
  {
    // if Office365
    using (var clientContext = TokenHelper.GetClientContextWithContextToken(
      hostWeb.ToString(),
      contextTokenString,
      Request.Url.Authority))
    {
      . . .
    }
  }

  . . .
}

Read further to understand hybrid authentication 

Thank you 


Monday, May 13, 2013

How to access REST Endpoint In SharePoint App in SharePoint Online?

1)In your SharePoint Online site (Office 365) create site collection using Developer site template
(In Ribbon-->Admin-->SharePoint)

2)In SharePoint App store , search for NAPA and Install this app.

3)Now create new Project and set the REST endpoint as shown in following images












4)In Explorer, Open the Default.aspx
and put the code as in following snippet.

<!-- Placeholder for the remote content -->
<span id="categories"></span>

<!-- Add references to the JavaScript libraries. -->
<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">
(function () {
    "use strict";

    // Prepare the request to an OData source
    // using the GET verb.
    var context = SP.ClientContext.get_current();
    var request = new SP.WebRequestInfo();
    request.set_url(
        "http://services.odata.org/Northwind/Northwind.svc/Categories"
        );
    request.set_method("GET");

    // We need the response formatted as JSON.
    request.set_headers({ "Accept": "application/json;odata=verbose" });
    var response = SP.WebProxy.invoke(context, request);

    // Let users know that there is some
    // processing going on.
    document.getElementById("categories").innerHTML =
                "<P>Loading categories...</P>";

    // Set the event handlers and invoke the request.
    context.executeQueryAsync(successHandler, errorHandler);

    // Event handler for the success event.
    // Get the totalResults node in the response.
    // Render the value in the placeholder.
    function successHandler() {

        // Check for status code == 200
        // Some other status codes, such as 302 redirect
        // do not trigger the errorHandler. 
        if (response.get_statusCode() == 200) {
            var categories;
            var output;

            // Load the OData source from the response.
            categories = JSON.parse(response.get_body());

            // Extract the CategoryName and Description
            // from each result in the response.
            // Build the output as a list.
            output = "<UL>";
            for (var i = 0; i < categories.d.results.length; i++) {
                var categoryName;
                var description;
                categoryName = categories.d.results[i].CategoryName;
                description = categories.d.results[i].Description;
                output += "<LI>" + categoryName + ":&nbsp;" +
                    description + "</LI>";
            }
            output += "</UL>";

            document.getElementById("categories").innerHTML = output;
        }
        else {
            var errordesc;

            errordesc = "<P>Status code: " +
                response.get_statusCode() + "<br/>";
            errordesc += response.get_body();
            document.getElementById("categories").innerHTML = errordesc;
        }
    }

    // Event handler for the error event.
    // Render the response body in the placeholder.
    // The body includes the error message.
    function errorHandler() {
        document.getElementById("categories").innerHTML =
            response.get_body();
    }
})();
</script>

5) to set different app permissions, click on 'Settings' in explorer and make sure  that following permissions  are not required for App to run.

Saturday, May 4, 2013

SharePoint Search Refinement Webpart in SharePoint 2013

In SharePoint 2010,In Search Center Site,refinements were auto populating depending on managed properties mapped to crawl property and When metadata column was created for particular document library

In SharePoint 2013 ,refiners are configurable.To verify this
Edit Search Center Page-->Edit Refiner Webpart --> Click Choose refiners .
and hit on preview button



Tuesday, April 30, 2013

SharePoint Result Sources in SharePoint 2013 Search


1)In Site Settings page ,See the Search section and click Result source

2)Copy the required Result source and provide the appropriate name.
  Launch the query builder and modify the result source and save the changes.


3)will add some more stuff  soon....

Sunday, March 10, 2013

How To Deploy Custom List Forms With Data Form Webpart?

To Deploy list instances along with Custom New/Edit/Display Form, You can follow these steps
1)In SharePoint Designer
 Select  List and Librararies --->Preview Custom Forms in Browser-->Edit this Page in browser
 and export the DataForm Webpart

2)Edit the .Webpart file in Visual studio to remove  parameters for WebUrl (ctrl F +search for Weburl and remove it)
replace all occurrence of ListID to ListName and the Guid with the Name Of the List
and save .webpart file
In Webpart Properties remove ListName Property

3)Upload this Deployable Datformwebpart and Edit the Custom List Pages to Add this new Webpart
 and Remove the existing one.
In Visual Studio, Create the Module under ListInstance folder to provision Custom Form
(You can get this module from exported wsp to Visual studio of required site template which is saved as wsp)
Open the elements.xml file of the module and replace the CData of Dataform Webpart obtained in step 2
(If you need additional help , pls drop a comment)

4)Now to Deploy with ListInstance Follow the steps given here

After reading this artical I found that, Dataform Webpart will not work as it depends on List Guids

Also Check this url, which dynamically replaces tokens with Guids and custom pages are the sites pages

Create an Item in an External List on the Server

1)While creating ListItem in an external List
you must have visited this msdn How to

2)Have you come across this error for Authenticated users?
Failed to create a list item for this external list based on the Entity (External Content Type) 'ECT' in EntityNamespace '/sites/test space'. Details: Credentials were not found for the current user within the target application 'ECT'. Please set the credentials for the current user.

3)Edit the external Content Type,and make sure in Connection properties ,Authentication mode is selected to 'BDC Identity'

Thursday, February 28, 2013

SPLong Operations VS Wait Modal Poup

1) If you need to show the wait  screen when the list of activities being executed in behind the scenes
  SPLong Operation is pretty good solution.

2) In the scenarios  Where Client Object Model is used in huge,Following source will definitely help you


<script type="text/javascript">

function RedirectTo() 
{
  window.location = "New Page Url";      
  
}

function showWaitScreen() 
{
  
window.parent.eval("SP.UI.ModalDialog.showWaitScreenWithNoClose('Please Wait', 'Redirecting to new page...', 76, 330);");
  setTimeout(RedirectTo, 1500);
}
  
ExecuteOrDelayUntilScriptLoaded(showWaitScreen, "sp.js");
        
 </script>

Questions and Comments are welcome !!!