SharePoint CAML Query and Scope attributes

Below article is above understanding scope attribute in CAML query. Suppose you have a document library where documents are stored with some folder structure.

Understanding Scope and its possible values

Default  – No specifying scope attributes, it will only returns all the files under root folder of document library. It won’t go return any files under a folder though applicable based on where condition

Recursive – By specifying scope as Recursive, it will returns files under document library including files under sub folders but not at second  level folder(folder inside folder).

FilesOnly – By specifying scope as FilesOnly, it will returns files only and exclude folders.

RecursiveAll – By specifying scope as RecursiveAll, it will returns all the files under document library including all the folder and sub folder inside folder.

Below are couple of scenarios to understand the same.

Scenario 1 – Retrieve file under specific folder, here folder path is “/folder/subfolder1” is relative path. Please note here example is based on Managed CSOM

List DocumentsList = clientContext.Web.Lists.GetByTitle("SharedDocuments");
CamlQuery camlQuery = new CamlQuery();
camlQuery = new CamlQuery();
camlQuery.ViewXml = @"<View Scope='RecursiveAll'>
                                    <FieldRef Name='FileDirRef'/>
                                    <Value Type='Text'>
                        <RowLimit Paged='TRUE'> 30 </RowLimit>
ListItemCollection listItems = DocumentsList.GetItems (camlQuery);

Scenario 2 – Find all zip files within a document library, please note here example is based on JSOM.

var files = [];
var clientContext = new SP.ClientContext.get_current();
var oList = clientContext.get_web().get_lists().getByTitle('SharedDocuments');    
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml("<View Scope='RecursiveAll'><Query><Where>" + 
                "" +
                "<Contains><FieldRef Name='FileLeafRef' /><Value Type='Text'>.zip</Value></Contains>" + 
this.collListItem = oList.getItems(camlQuery);
clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));        

function onQuerySucceeded(sender, args) {
    var listItemEnumerator = collListItem.getEnumerator();
    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();  

function onQueryFailed(sender, args) {
    //Handle Error

Hope this  helps…Happy Coding..!!!

How to Test Your Local Web Sites on Your Mobile Devices Using XAMPP

Undoubtedly, every one of us would agree that Smart phone and new mobile devices have changed the world we live in. Everyone is so much dependent on smart phone that it has become very much necessary for the web site designers to make sure that the website being developed works well on
mobile devices also.
This smart phones and tablets have changed the development methodology or approach towards user experience and design. It won’t be incorrect to say that website designers and developers have yet not found a profound solution for challenge to keep same look and feel across different browsers
(IE, Firefox, chrome, safari etc…). And here comes a new one, support your website on various mobile devices and tablets at different resolutions.

To meet this challenge we have two design methods “Responsive web design” and “Adaptive”. Also it does not matter which one you are using until and unless the user is able to view website easily and effectively. But one of the problem designers/developers face is how to test their web application on actual devices during development. All web developers today should be testing their websites on mobile devices. I don’t mean simulators or emulators; I mean real-life devices that you hold in your hand. Simulator does not give us actual results because it is still running on desktop system.

Wouldn’t it be nice to test your local website on local computer from actual mobile devices? Let us see how we can do that.

1. It is being assumed that XAMP/WMAP or MAMP is installed in you system and you are doing local development using any of the Apache, MySQL and PHP webserver.
2. Your local computer and your mobile device is connected to same network via WIFI or any other connection. (Both desktop and mobile has to be on same network).
Step 1 – Go to XMAPP control panel and make sure you apache and MySQL is working. Also make
sure your website is running.

Step 2
Find your IP address of local computer.
Run CMD as administrator
And on CMD screen type ipconfig and the screen will appear with text

Step 3
Browse you site with URL on your local browser, this is to make sure site is working with IP address also.

Suppose you website is located at localhost/demosite/
It should be brows able with
Note – Make sure you setup BASE URL with IP ADDRESS
Step 4
Point your iPad or iPhone web browser to your IP address
You now have your IP address. It may look something like Now, for the moment of truth, open a browser on your device at try browsing to the  directory using the IP address. In my case, I entered You’re now testing a website on your
computer from a remote device like an iPad.

That was easy, now you can do test and fix responsive mobile specific bugs easily before moving site to internet.

Hope this will help. Happy coding..!!!

Enable Magento SOAP api from backend to enable client application to connect with Magento Store.

If you wanted to connect to Magento store from any external application, then you need to enable SOAP api interface from backend and create a user and role based on your requirement. Basically enable Enable Magento SOAP api from backend to enable client application to connect with Magento Store.

Below are steps which need to be followed.

Login to Magento back end with admin credentials

Go to System->Webservices->SOAP/XML RPC Roles

Click on Add new Role

Provide role name

Click on Role Resources

If you wanted a role to be created who has access to all the resources then Select All and Save role

For customized role and its permission select Custom from dropdown and select the API modules/methods to which you wanted this particular role to have access to. This might help you in creating different role for different client applications.

Click on Save and confirm roles is added on role list page.

Now let us go and create a new User.

Go to System->Webservies->SOAP/XML RPC users

Click on Add new user

Provide below information

User name This would be the user name which will be used by client application to connect and retrieve session id.
First Name First Name of User
Last Name Last name of user
Email Email address of user
API Key/API Key Confirmation This is important and secret key which client application will use/pass while retrieving session id. This has to be secret and cannot be shared with unknown sources.
Account Status Active

Click on user Role on left side

Select the role which we created above

Click Save and you are done

Now you can go ahead and connect to Magento SOAP api from client application

Below is sample php code to connect to Magento SOAP api and retrieve session id and get list of products for any particular category. Code is for demonstration purpose only.

Click on user Role on left side

Select the role which we created above


Click Save and you are done

Now you can go ahead and connect to Magento SOAP api from client application

Below is sample php code to connect to Magento SOAP api and retrieve session id and get list of products for any particular category. Code is for demonstration purpose only.

try { 
if($_GET['ver'] == '2') { 
$client = new SoapClient(SOAP_WSDL2, array('trace' => 1,'cache_wsdl' => 0)); 
echo "<br>version 2 <br>"; 
else { 
$client = new SoapClient(SOAP_WSDL,array('trace' => 1,'cache_wsdl' => 0)); 
echo "<br>version 1 <br>"; 
$session = $client->login(SOAP_USER, SOAP_PASS); 
$result = array(); 
try { 
if($_GET['ver'] == '2') 
$result = $client->catalogCategoryAssignedProducts($session,'233'); // 233 here is category id and this method will returns us all the product under this category id 
var_dump ($result); 
else { 
$result= $client->call($session, 'catalog_category.assignedProducts', '233'); // 233 here is category id and this method will returns us all the product under this category id 
var_dump ($result); 
catch (SoapFault $exception) 
{ echo 'EXCEPTION='.$exception; } 
echo "<br>end test<br>"; 
catch (Exception $e)
echo var_dump($e); throw $e; 

Hope this help….Happy Coding!!!!

Asp.Net Page Postback from Javascript

If you need to do page postback from javascript, this one is for you…
Today I came across situation where we were using Jquery calendar but we needed postback as soon as date is selected by user.

Step 1- Bind Javascript function to onselect event of Jquery calendar

onSelect: function(dateText, inst) {

Above will make sure page is post back as soon as date is selected by user.
first parameter is eventtarget, second paramerter is eventargument.
Same can be used in any java scripts functions

Step 2 – Check Event Target in Request.Forms parameters and do whatever you want man  like below

if(Request.Form.Params.Get(“_EVENTTARGET”) == “buttonidoranyvalue”) {
//do whatever you want 

Hope this helps…Happy Coding!!!! Postback Mechanism(doPostBack function)

Let us understand how postback works

What is __doPostBack function in javascript and what it does? In all the web server controls except Button and ImageButton (discussed at the end) use javascript __doPostBack function to trigger postback. This behavior is known as postback mechanism.

To better understand this function lets go step by step. Lets take any web server control except Button and ImageButton on a sample aspx page.


<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_Click" Text="LinkButton" />

///Code behind

protected void LinkButton1_Click(object sender, EventArgs e) { }

Run the page in browser and view it source.


function __doPostBack(eventTarget, eventArgument) {

    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {

        theForm.__EVENTTARGET.value = eventTarget;

        theForm.__EVENTARGUMENT.value = eventArgument;





<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" />

<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT" value="" />

<a id="LinkButton1" href="javascript:__doPostBack('LinkButton1','')">LinkButton</a>

As you can see _doPostBack function takes two arguments viz. eventTarget and eventArgument. Moreover two hidden fields, “__EVENTTARGET” and “__EVENTARGUMENT,” are automatically declared which are used to store values of ‘eventTarget’ and ‘eventArgument’ respectively.

When LinkButton1 is clicked, __doPostBack function in javascript is called passing it respective arguments, in this case eventTarget is LinkButton1 and eventArgument is empty, these values are stored in respective hidden fields i.e. they are added to form parameter collection and finally the form is submitted. On server, ASP.NET retrieves and uses the values from form collection and understands which control caused the postback.

Ok if you have some confusion on these values are retrieved, lets do it ourselves to clear the things out. Take another control on web form, say another link button ‘LinkButton2’.

Insert break point on Page_Load event and hit F5. Click on LinkButton1, check the values that are retrieved in Page_Load event.

As you see __EVENTTARGET key returns the value of the control that caused postback, here LinkButton1. Now click on LinkButton2 and check the value you get, it will be “LinkButton2”. This is how the postback mechanism works through use of javascript __doPostBack function.

Button and ImageButton

These are the only two controls which cause postback in Rest (as explained above) use javascript __doPostBack function and post the form (ASP.NET postback mechanism). In other words these two controls use client browser’s submit behavior and hence they do not use __doPostBack function.

However you can make Button to use postback mechanism by making use of Button.UseSubmitBehavior property (this property is not available for ImageButton control). UseSubmitBehavior property is of type bool and decides whether Button should use client browser’s submit behavior (Default. value = true) or postback mechanism (value = false).

Lets take two Button control on page:

<asp:Button ID="Button1" runat="server" Text="Uses browser submit behavior" UseSubmitBehavior="true" />

<asp:Button ID="Button2" runat="server" Text="Uses postback mechanism" UseSubmitBehavior="false" />


Note that you don’t have to specify UseSubmitBehavior=”true” explicitly as it is the default value/behavior. I have added it just for the sake of understanding. Now run this page and view its source in browser, you will these buttons rendered as follows:

<input type="submit" name="Button1" value="Uses browser submit behavior" id="Button1" />

<input type="button" name="Button2" value="Uses postback mechanism" onclick="javascript:__doPostBack('Button2','')" id="Button2" />


Button2 for which we set UseSubmitBehavior property to false, will now use _doPostBack function to submit the form.

Hope this helps…Happy Coding!!!!

How to add JS or css file reference to all pages with custom action ?


  • Suppose you wanted to add JS file or css file reference to all the pages in your site collection via javascript but you are not allowed to edit master page.
  • Suppose you wanted to do branding like displaying message or modifying css to all the site collections then it would be difficult to go and edit css of each site collection. To overcome this we can write a utility which will iterate through each target site and add js and css reference.


  • Custom action functionality to add ScriptLink can be used to add JS and CSS file references to all the pages without using master page
  • We can do do this JSOM or managed CSOM based on our requirement

Using JSOM – You can add below function in any JS file or content editor webpart and call GetCustomActionsOfWeb from click event of button.

If you are calling on page load or something, make sure you wait till sp.js is loaded and then call your function.

ExecuteOrDelayUntilScriptLoaded(GetCustomActionsOfWeb, 'sp.js');

function GetCustomActionsOfWeb(){

clientContext = new SP.ClientContext.get_current();

var hostWeb = clientContext.get_web();

hostWebCustomActions = hostWeb.get_userCustomActions();



clientContext.executeQueryAsync(AddNewCustomAction, ErrorInGettingCustomActions);


function AddNewCustomAction(){

var customAction = hostWebCustomActions.add();



customAction.set_scriptSrc('~SiteCollection/Site Assets/jquery-1.11.1.min.js');



clientContext.executeQueryAsync(onSuccess, OnFail);


function ErrorInGettingCustomActions(){

alert('Error in getting custom actions...');


function onSuccess(){

alert('Added Script Link Successfully.')






function OnFail(){

alert('Enable to add script link via custom action');



Using CSOM

private  void AddCustomAction(string SCURL)


           using (ClientContext context = new ClientContext(SCURL))


               // Check URL is root site or web

               Web oWeb = context.Web;

               UserCustomActionCollection collCustomActions = oWeb.UserCustomActions;

               //var serverURL =  oWeb.;

               context.Load(oWeb, webSite => webSite.UserCustomActions);


               //******** Delete file script link reference if already exsits in page ********

               int actionCount = oWeb.UserCustomActions.Count;

               for (int i = actionCount - 1; i >= 0; i--)


                   // if (oWeb.UserCustomActions[i].ScriptSrc != null && (oWeb.UserCustomActions[i].ScriptSrc.Contains(Constants.ScriptFileNames.JqueryRef) || oWeb.UserCustomActions[i].ScriptSrc.Contains(Constants.ScriptFileNames.HeaderFile) || oWeb.UserCustomActions[i].ScriptSrc.Contains(Constants.ScriptFileNames.StickyFooter)))

                   if (oWeb.UserCustomActions[i].ScriptSrc != null && (oWeb.UserCustomActions[i].ScriptSrc.Contains(Constants.ScriptFileNames.HeaderFile) || oWeb.UserCustomActions[i].ScriptSrc.Contains(Constants.ScriptFileNames.StickyFooter)))


                       Console.WriteLine(oWeb.UserCustomActions[i].Title + " Found");






                   UserCustomAction oUserCustomAction = collCustomActions.Add()

                   oUserCustomAction = collCustomActions.Add();

                   oUserCustomAction.Location = "ScriptLink";

                   oUserCustomAction.Sequence = Constants.sequenceCounter + 2;

                   oUserCustomAction.Title = "Custom Branding";

                   oUserCustomAction.Description = "Custom branding Description.";

                   oUserCustomAction.ScriptSrc = SCURL + "/Site Assets/" + "branding.js"; // thi sis custom js file






Hope this helps…Happy coding..!!!

How to get data from SharePoint List when threshold value is crossed ?


  • Suppose you have List Employees which has more than 100000 rows(1 lakh)
  • Threshold limit set by administrator is 5000(default).
  • Employees are categorized in 3 department so we have one column Department which hold employee’s department. Each department has around 33000 employees.
  • Department column is indexed.


  • Create a page which displays Employees in Jquery datatable(custom view) by calling GetListItems using spservices.js
  • Page will have a dropdown  for department which user can select and data will be filtered accordingly.
  • All the data needs to be displayed at once.


  • As each department has more than 33000 items, CAML query will fail with Threshold limit error.

Alternate solution approach.

  • Get the data in batch by querying multiple times. Though this is not effective but still it might be required when you need to display all data at once on filter.


  • Get data in batches by using SharePoint CAML query paging technique and specifying row limit.
  • We will get data in batch of 4999 rows at a time and merge data each time till all the rows are returned.
  • Same Caml query will be used with CAMLQueryOptions and sending ListItemCollectionPositionNext
//Glboal variables in your js file which will be used in below functions.

var isThreshold = false;

var dtEmployees;

var tempEmployeeData;

function GetDataFromList(strlistName)


var queryString = "";

queryString = "<Query>"+


"<Eq><FieldRef Name='Company' /><Value Type='Text'><![CDATA[" + "XYZ" + "]]></Value></Eq>" +



"<FieldRef Name='Modified' Ascending='TRUE'/>"+




operation: "GetListItems",

async: false,

listName: strlistName,

CAMLRowLimit: 4999,

CAMLQueryOptions: "<QueryOptions><Paging ListItemCollectionPositionNext='"+position+"' /></QueryOptions>",

CAMLQuery: queryString,  

CAMLViewFields: "<ViewFields>" +

"<FieldRef Name='Title'/><FieldRef Name='EmployeeName' /><FieldRef Name='Department' />" +


completefunc: function (xData, Status) {

if(Status.toLowerCase() == "success")


// below xml node will return us next position, save it for next query

position = $(xData.responseXML).SPFilterNode("rs:data").attr("ListItemCollectionPositionNext");


dtEmployees = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({

mapping: {

ows_ID: {mappedName: "ID", objectType: "Counter"},

ows_Title: {mappedName: "Title", objectType: "Text"},

ows_EmployeeName: {mappedName: "EmployeeName", objectType: "Text"},

ows_Department: {mappedName: "Department", objectType: "Text"}



// Threshold exceed.. loop and fetch more than 5000 records.

if(position != undefined && position != "undefined" && position != "")


position = position.replace("&","&amp;");

if(tempEmployeeData == undefined || tempEmployeeData == "undefined" || tempEmployeeData == "")


tempEmployeeData = dtEmployees;




tempEmployeeData = tempEmployeeData.concat(dtEmployees);


isThreshold = true;

GetDataFromList("EmployeesInfo"); // calling same function again for further iteration.




if(tempEmployeeData != undefined && tempEmployeeData != "undefined" && tempEmployeeData != "")


tempEmployeeData = tempEmployeeData.concat(dtEmployees);

dtEmployees = tempEmployeeData;

tempEmployeeData = "";


isThreshold = false;

ProcessData(dtEmployees); // this can be your custom function which will be use final dtEmployees json object to processing.




alert("Error ---\n" + $(xData.responseXML).find("errorstring").text());






Hope this helps…Happy Coding..!!!

What is Sharepoint ?

As defined by Wikipedia

Microsoft SharePoint is a Web application platform developed by Microsoft. First launched in 2001,[3] SharePoint has historically been associated with intranet, content management and document management, but recent versions have significantly broader capabilities.

As defined by Microsoft

Organizations use SharePoint to create websites. You can use it as a secure place to store, organize, share, and access information from almost any device. All you need is a web browser, such as Internet Explorer, Chrome, or Firefox.

Other definitions

At its most basic definition SharePoint is a web application from Microsoft that enables organizations to work more efficiently by letting users share documents, data and information. There are multiple SharePoint products for organizations to choose from, each offering a unique set of benefits.

In Simple terms
SharePoint is a:

  • Document management server
  • Web content management server
  • Portal solution
  • Search engine
  • List-based repository
  • Collaboration site
  • Replacement for file shares
  • etc etc…

…to summarize in one sentence what SharePoint is I would say:
Sharepoint is Microsoft’s Web OS.

Finally as explained by MSDN

The following is a selection of some of the most important things that SharePoint is:

  • A portal server with delegated administration. SharePoint enables information workers (IW) who have no knowledge of website design or website administration to create, almost instantly, attractive and functioning websites. This relieves information technology (IT) departments from the burden of creating and administering the sites, and it empowers the IWs to create their own sites for teams, blogs, wikis, and other purposes.
  • A groupware application kit. SharePoint provides a platform on which IWs can create collaboration solutions that include document libraries and workspaces, workflows, wikis, blogs, and team-oriented lists, such as Events, Announcements, and Tasks. Microsoft SharePoint Workspace (formerly Microsoft Office Groove 2007) provides an offline experience for these collaboration solutions.
  • A workflow host. Business processes can be systematized and modeled with workflows that are triggered by associated events; for example, the addition of a document to a document library.
  • A content management application. SharePoint Server Enterprise Content Management (ECM) features include document management, records management, and web content management.
  • A Business Intelligence (BI) application kit. The Microsoft Business Connectivity Services (BCS) features of SharePoint enable data from non-SharePoint sources, such as a SAP installation or Oracle database, to be accessed (read/write) just as if it were an ordinary SharePoint list.
  • The operating system of an intranet. SharePoint can provide for an intranet many of the functions that an operating system provides for a computer, including storing and copying files, hosting services, starting applications, and securing data. (This is not to imply that SharePoint can only be used on an intranet. SharePoint can also host extranet and Internet-facing solutions.)
  • A host for services. SharePoint deployments make data available through a client object model, the REST-based Windows Communication Foundation (WCF) Data Services (formerly ADO.NET Data Services), and many out-of-the-box ASMX web services. In addition, the SharePoint Service Application Framework provides a platform that enables developers to build scalable middle-tier services that can provide data or processing resources to other SharePoint features.
  • A data store. SharePoint stores data as multicolumn lists in a Microsoft SQL Server database. You can query the data by using LINQ and also using Collaborative Application Markup Language (CAML). The data can be mirrored, backed up, restored, and, depending on the edition of SQL Server being used, you may be able to take snapshots of the data store.
  • A data and processing layer for multiple user interfaces (UIs). Besides its native UI of webpages (including special versions for mobile devices), which can contain ECMAScript (JavaScript, JScript), SharePoint also supports access from Microsoft Silverlight applications and the Microsoft SharePoint Workspace client application. With the SharePoint client object model, you can access SharePoint using Windows Presentation Foundation (WPF), Windows Forms, or any other managed code application

Hope this helps…Happy Coding!!!!

Why SharePoint is popular ?

File Sharing SharePoint originally became popular because it was an easy way to share documents on the web. Many organizations that adopted SharePoint in the 2003 versions capitalized on the ability to upload documents to Document Libaries and share those documents with others.

Company Extranets One great example of this web based sharing, is a company extranet where users are not all in one location or authentication domain. Using form based authentication, accounts can be created for people across physical and company boundaries. By allowing one place for shared documents around a task rather than a corporate entity, SharePoint goes way beyond the common file share.
Content Management There are plenty of other Content Management Systems, but MOSS incorporated the functionality of the previously name Microsoft Content Management System which itself often cost more than MOSS alone. Check out this large list of public websites and blogs hosted on SharePoint And that is not all of them.
Search Search is greatly improved in SharePoint technologies. Search results are security trimmed, relevant and performant unlike the previous version.
Other reason
The OOB features are 1/10th of the whole story. Sharepoint exposes a comprehensive .Net object model that lets you customize the thing to your hearts content. People are coding amazing things with Sharepoint. With the object model, you can build and customize sites via code, in response to external events. You can write custom “web-parts” (controls hosted on special pages) that consume both internal (sharepoint) and external data.

Why companies end up going with Sharepoint:

  • they get it a very low cost (oftentimes free) because they are Microsoft partners
  • they are already so dependent on Microsoft products that Sharepoint seems to be the logical choice
  • a proper vendor evaluation never takes place and instead the company goes with the apparently easiest and lowest cost alternative
  • enterprise security from a reliable vendor
  • companies know that Microsoft isn’t going anywhere whereas some of the other collaboration vendors in the space might not be around the long
  • it was one of the earlier collaboration platforms available (initial release was actually in 2001)
  • they focus on what Microsoft says it can do and is good vs what it can really do and is good at (marketing vs reality)

Hope this helps….Happy Coding!!!!

Difference between List and Library

Although in most of the UI and API they can be manipulated the same way, there are some significant differences between Lists and Libraries. The latter is a specialized type of the former.

Can have attachments
Have major versions only
Do not have Check-in/Check-out features

Cannot have attachments (files are directly in the library)
Have both minor (draft) and major (published) versioning
Have Check-in/Check-Out
Publishing Libraries can use Page Layouts
Have Unique Document Ids out of the box
In code, you can always obtain an SPList from a SPDocumentLibrary but not the other way around.

Hope this helps…Happy Coding!!!!