Showing posts with label list. Show all posts
Showing posts with label list. Show all posts

Sunday, 30 August 2015

How to programmatically get the Titles and Guids of all the lists in a Sharepoint site.

Hi all, Below code is used to get the details of all lists in the Site using CSOM.
I have logged the details in console. You can manipulate the data as per the requirement.

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


function retrieveAllListProperties() {

    var clientContext = new SP.ClientContext(siteUrl);
    var oWebsite = clientContext.get_web();
    this.collList = oWebsite.get_lists();
    clientContext.load(collList);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded),       Function.createDelegate(this, this.onQueryFailed));

}

function onQuerySucceeded() {

    var listInfo = '';
    var listEnumerator = collList.getEnumerator();
    while (listEnumerator.moveNext()) {
        var oList = listEnumerator.get_current();
        listInfo += 'Title: ' + oList.get_title() + ' Guid: ' + oList.get_id().toString() + '\n';
    }
    console.log(listInfo);
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}


Happy Coding :)

Wednesday, 15 July 2015

Programmatically getting the values from a SharePoint list view

Hi,
 Today I will share the code for getting the values of the items in a particular view through Client Side Object Model.
For this we have to make 2 requests. First request is to get to know which view & view query and second would be for getting the values from that view.

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

// First request
function getItemsFromView()
{
    var context = new SP.ClientContext.get_current();
    var list = context.get_web().get_lists().getByTitle('List Name');
    var view = list.get_views().getByTitle('View Name');
    context.load(view);
    context.executeQueryAsync(
        function (sender, args) { getItemsFromList('List Name', "<View><Query>" + view.get_viewQuery() + "</Query></View>") },
        function(sender, args) {alert("error: " + args.get_message());}
    );
}
//Second Request
function getItemsFromList(listTitle, queryText) {
    var context = new SP.ClientContext.get_current();
    var list = context.get_web().get_lists().getByTitle(listTitle);
    var query = new SP.CamlQuery();
    query.set_viewXml(queryText);
    var items = list.getItems(query);
    context.load(items);
    context.executeQueryAsync(
        function () {
            var listItemInfo = '';
            var listEnumerator = items.getEnumerator();
            var i = 0;
            while (listEnumerator.moveNext())
            {
                i++;
            }
            alert("items retrieved: " + i);
         
        },
     
function (sender, args) { alert("error in inner request: " + args.get_message()); }
   );
}

Hope this helps. Happy Coding :)

Monday, 6 July 2015

Programmatically Diasable List Throttling for a specific List in SharePoint - Powershell

Hi All,

 Today we will see about "How to Diasable List Throttling for a specific List".

SP2010 introduces list throttling settings that allow us to specify how many items a user can query before the throttle kicks in and aborts the query. This applies to both the queries that retrieve through SharePoint UI and from custom code. Default limit is 5000 items per list. While exceeding this limit results in display of an error message. We can override it by calling RequestThrottleOverride on the SPQuery object. This will allow us to execute large unsafe queries.

SharePoint 2010 provides Administrators to control a limit of how many items to be retrieved from the lists at a time using User Interface or Object Model.

SharePoint by default set some limitation to your web application to make sure that performance is good even when data increasing. These limitations has been tested and carefully chosen by SharePoint Team and Microsoft does not recommend changing these value.


List Throttiling feature is webapplication level.
If we want to change the limits for the whole web app,
From Central Administration
1. Go to SharePoint 2010 Central Administration
2. Under Application Management, click "Manage Web Application"
3. Choose the web application that you want to change. On the ribbon click "General Settings" and then "Resource Throttling"
4. Change throttling settings and click OK.

To override the default throttling settings. just execute the below powershell to add list items more than the threshold limits.

web = Get-SPWeb -Identity http://mysite
$web.AllowUnsafeUpdates = $True
$list = $web.Lists["ListName"]
$list.EnableThrottling = $False
$list.Update()
$web.AllowUnsafeUpdates = $False
$web.Update()
$web.Dispose()

Thanks for your time.. Happy SharePointing..