Saturday, 6 September 2014

Nav items using CSOM

$(document).ready(function () { SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function () { pageloaddetails(); }); });

    //This function is called on the page load and it fetches the static information for the Navigation bar
    function pageloaddetails() {
     try {

            var context = new SP.ClientContext.get_current();           
                                      var web = context.get_web();
                                     
            var list = web.get_lists().getByTitle('Navigation Configuration');           
            var query = '';
            var camlQuery = new SP.CamlQuery();
            camlQuery.set_viewXml(query);
            this.listcollection = list.getItems(camlQuery);
            context.load(this.listcollection, 'Include(Title,ItemText)');
            context.executeQueryAsync(Function.createDelegate(this, this.Received), Function.createDelegate(this, this.failed));
            //return false;
        }
        catch (e) {
            alert(e);
        }
    }
    //This method is called on the success of pageload function.
    function Received() {
        var title = "";
        var htmlNav = "";
       
        var ListEnumerator = this.listcollection.getEnumerator();      
        while (ListEnumerator.moveNext()) {
            var currentItem = ListEnumerator.get_current();
            if (currentItem.get_item('Title') != null) {
                if (currentItem.get_item('Title') != "") {
                       if  ( currentItem.get_item('Title') == "Topnav"){
                    htmlNav = currentItem.get_item('ItemText');
                    }                   
                }
            }
          document.getElementById("topNavDiv").innerHTML = htmlNav;
        }
       
    }
    function failed(sender, args) {
        alert('failed. Message:' + args.get_message());

    }

CSOM

Functionality we are trying to achieve:
On page load, the web part should show us the info for title “Tom” on the page. That is on page load user should see name and details of the user “Tom” pulled from the “Info” list.
<script type="text/javascript">
    //Make sure SP.js is loaded before using it
    $(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(infoLoad, "SP.js"); });

    //This method is called on the page load and this will load the details of the user info from the "Info" list.
    function infoLoad() {
        try {
     //hardcoding the title value. You can easily make it dynamic by pulling it from some control in case it is needed
     var title = " Tom";
            var context = new SP.ClientContext.get_current();
            var web = context.get_web();
            var list = web.get_lists().getByTitle('Info');
            var query = '<View Scope=\'RecursiveAll\'>' +
                        '<Query>' +
                            '<Where>' +
                            '<Contains>' +
                                '<FieldRef Name=\'Title\'/>' +
                                '<Value Type=\'Text\'>' + title + '</Value>' +
                            '</Contains>' +
                            '</Where>' +
                        '</Query>' +
                             '</View>';
            var camlQuery = new SP.CamlQuery();
            camlQuery.set_viewXml(query);

            this.productcollection = list.getItems(camlQuery);
//Mentioning few properties to pull from the list
            context.load(this.productcollection, 'Include(Title, UserDetails)');
//Defining the fallback methods
            context.executeQueryAsync(Function.createDelegate(this, this.productsReceived), Function.createDelegate(this, this.failed));
            return false;
        }
        catch (e) {
            alert(e);
        }
    }

    //This method is called on the success of the infoLoad function and it passes list colection to this function.
    function productsReceived() {
        var TextFiled = "";
        var ListEnumerator = this.productcollection.getEnumerator();

        while (ListEnumerator.moveNext()) {
            var currentItem = ListEnumerator.get_current();


$('#<%=lblName.ClientID%>').html(currentItem.get_item(' Title '));              $('#<%=lblUserDetails.ClientID%>').html(currentItem.get_item('UserDetails'));

        }
        return false;
    }
//Defining the failed method
    function failed(sender, args) {  

        alert('failed. Message:' + args.get_message());
    }
</script>
//Defining 2 controls to display the data. You can use HTML controls. Just to show the syntax to use server side controls on JQuery, the below controls are used
<div class="description">
                <h2>
                    <asp:Label ID="lblName" runat="server"></asp:Label></h2>
                <p>
                    <asp:Label ID="lblUserDetails" runat="server"></asp:Label>
                </p>
</div>

Deploy the solution to a site, add the web part to a page and check Tom’s data on the page.

Thursday, 4 September 2014

Power shell reference guides

http://sharepoint.rackspace.com/powershell-commands-for-sharepoint-admins
http://www.spsdemo.com/lists/powershell/commands.aspx 

Tuesday, 12 August 2014

Save & Send - Save to SharePoint option missing in file menu (excel/doc etc.)

please refer to this link
http://www.cloudnetworks.com.au/support/save-to-sharepoint-is-missing-from-the-file-menu-in-word/ 

Sunday, 1 June 2014

Power shell command to check event receivers associated to a list/library

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Get the web
$Web = Get-SPWeb "<website>"

#Get the Target List
$List = $Web.Lists["Document"]

#Retrieve all event receivers associated with the list
$List.EventReceivers | Select Id, Type, Assembly, Class | FL

Tuesday, 6 May 2014

Things to keep in mind while developing apps for SharePoint which expects anonymous user access

Things to keep in mind while developing apps for SharePoint which expects anonymous user access

A very common discussion topic in the SharePoint app world is , what are the points that we need to keep in mind when designing an app for anonymous users in a public site.

This issue comes up as there are many restrictions for anonymous users to access resources in a SharePoint world.

This MSDN documentation gives a clear documentation on the dos and don'ts while designing an app.
This link also guides developers, users and admins on the different considerations we need to keep in mind.

Saturday, 25 January 2014