Monday, May 26, 2014

Using disposable Objects in SharePoint

Its always best practice to use the "using" statement to create the SPSite and SPWeb (IDisposable) object.
So "using" statement will call the Dispose method in correct way for you. Not only that, Using operator ensures the Dispose methods has been called even exception occurred in the using statement block.

Despite SPSite and SPWeb objects are created as managed object majority of the object uses the unmanaged code and  memory to query the SQL table data.

If simply said, every SPSite and SPWeb object call the SQL related classes those are unmanaged code.

So mismanaged of the SPSite and SPWeb object leads to unnecessary application pool recycles,application crashes and high memory usage on all web front ends.

Best approach

 using (SPSite site = new SPSite(SPContext.Current.Site.Url))
                using (SPWeb web = site.OpenWeb()) //root site,if you work on the specific web you can use
                 //site.AllWebs["Child site's relative url"]


* here I using only the Url property of the current site from the SPContext not object.

You should not use the SPContext object for creating the new SPSite or SPWeb object to be used in the Using statement block when you trying to retrieve the site data inside the using statement block.
Because using statement will call the dispose method and it will throw the error like

Getting a error: Attempted to use an object that has ceased to exist. (Exception from HRESULT: 0x80030102 (STG_E_REVERTED))

Bad approach #1

          using (SPSite site = SPContext.Current.Site)
                using (SPWeb web = SPContext.Current.Web) // or SPWeb web = site.OpenWeb()

Bad approach #2
SPSite site = SPContext.Current.Site;
SPWeb web = SPContext.Current.Web

But you use approach # 2 with try,catch and finally with proper

Friday, May 16, 2014

SharePoint 2013 - App Publishing

When you are trying to publish the SharePoint App in SharePoint environment, there is couple of way to do.
First one,If you have administrator account to install the App in the site collection, you can deploy them manually by uploading the App Package (.app) file.

In your Office 365 account, you will find the SharePoint's new site collection type "App Catalog" there you can upload the package file to distribute the app within your tenancy.

But if you want to publish the Apps only for your company or specific user group then you need to have the App Catalog in your on-premise SharePoint farm.

In this case,you need to create the site collection "App Catalog" from the CA page or through PowerShell cmdlets.

Before proceeding this step,ensure you already configured the required app development configuration on your server.If you are about to configure please follow this link
Set up the development environment for SharePoint 2013

Creating App Catalog site in central administrator site.
Navigate to Central Admin site--> under apps header-> Manage App Catalog --> Create new app catalog
SharePoint App Publishing - figure 1

SharePoint App Publishing - figure 2

You can also choose to create the site through SharePoint PowerShell command.

New-SPSite http://win-49qfnhnl4fj/sites/AppCatalog -OwnerAlias "Local\Murugesan" –Template "APPCATALOG#0"

If you are planning to sell your app in market place then you must have to register in "Seller Dashboard"

Managing large list in SharePoint 2013

Its time for me to recollect and update my knowledge on "Managing the huge list and libraries" and limitation on SharePoint 2013.
Absolutely there are so many improvements done in SharePoint 2013 while comparing its predecessor.
Quick notable points are

Items in List and Library
50 million =  (50 * 10000000)
File size in attachment
50 Gig
Lookup columns in list
Can hold up to 8
Indexing the columns
Cannot be indexed on choices, multiline of text, Calculated columns, People picker with multi valued. External column, hyper link or photo columns and Lookup with multivalued
Query able per request using SharePoint UI
Default – 5000 items. Programmatically increase the (overriding the threshold) for admin user.
By default List View threshold for Auditors and administrator 20K
Working offline with Excel – Leverage the Chart, Pivot table against SP List
One way connection with MS Excel
Working offline with Access  Service
Advantage: Bi directional. When sync the data you are directly working with Service. Process the batches of 2000 items at a time.
Disadvantage: Access Service has its own threshold.  

Best practices to be followed when dealing with large list or library
1.       Create an index column and then use this column to create the filtered view.
2.       If the indexed column based view exceeding the List View threshold then continue your operation on off peak hours.
3.       You can also create the “Access App “to work with large list.
4.       Use the Excel to communicate with SharePoint List in off line mode. Add your records in excel and refresh the link.
5.       Use Meta data based filtration on List / Library.
6.       Create your personal view to get filtered that relevant to you.
7.       Enable the RSS Feed on your list and library.
8.       Manage your Task, Calendar, discussion and document library sync with Outlook.

Updates: (Managing the large list when you deal with Programmatically)

When you are working with huge list that’s any time can exceed the default thrash holding size.
You have to be careful when querying that list in order to retrieve or any against the data.
By default SPQuery will returns all fields in the list and sometime if your list had more than 8 lookup columns, then you can expect only 8 lookup columns and remains will silently suppressed in the result set.
You can optimize the CAML query that limits the rows (RowLimit) and required columns using ViewFields property.
Creating the index column in the SharePoint list considerably reduces the complexity and faster response on the loading time and as well as when you filter the list view.

·         You can create up to 20 columns as indexed.
·         Two types of Index available i.e. single column and compound (primary and foreign key).
·         Scan all columns in the list, if you find unique then you can index that column.

Content Iterator

Content Iterator API is a new mechanism to overcome the SPQueryThrottlingException on the list already exceeded the default throttling limit. This API uses the Callback pattern for segmenting the query for processing a single item at a time.

It has core method name “ProcessListItems” that takes 4 arguments i.e. List, Query, ProcessListItem and ProcessError.

Monday, May 05, 2014

SharePoint.NET Client Side Object Model - CSOM

SharePoint.NET Client Side Object Model(CSOM) is one of the approach to retrieve or CRUD operation on the SharePoint data on Client side application using ASP.NET web application,Windows application or Silverlight application.

 This web application must be hosted on where SharePoint server installed. You need to add the Microsoft.SharePoint.Client.Runtime.dll and Microsoft.SharePoint.Client.dll from the Common Files\Microsoft Shared\web server extensions\15\ISAPI location.

  Example code for retrieve the SharePoint list data and showing in ASP.NET grid.
        protected void btn_Click(object sender, EventArgs e)
            var fList = new List();
            FriendEntity entity = null;
            var context = new ClientContext("http://win-49qfnhnl4fj/");
            List friendList = context.Web.Lists.GetByTitle("Friends");
            var query = new CamlQuery {ViewXml = ""};
            ListItemCollection items = friendList.GetItems(query);
            foreach (var item in items)

                entity = new FriendEntity();
                entity.Prefix = item["Title"].ToString();
                entity.FirstName = item["First_x0020_Name"].ToString();
                entity.LastName = item["Second_x0020_Name"].ToString();
            grid.DataSource = fList;

        public class FriendEntity
            public string Prefix { get; set; }
            public  string FirstName { get; set; }
            public  string LastName { get; set; }

Thursday, May 01, 2014

Attempted to perform an unauthorized operation

Attempted to perform an unauthorized operation Visual studio,SharePoint Deployment

Error occurred in deployment step 'Activate Features': Attempted to perform unauthorized operation.
If you happen to see this error in your visual studio,then reason is your account has permission to access the Farm but not on your site collection where you trying to deploy the solution.

To resolve this issue Go to your Central Administration-->Application Management header-->Change Site collection administrators under "Site Collection" header.
Add your account try again the deployment.

Content Database ID in SharePoint

How to find out the Database Id {GUID} for the specific database on which you know by its name.
There is no GUI for this requirement except the GUID append with the URL.

Step 1
In your Central Adminstration Page navigate to "_admin/CNTDBADM.aspx".
This page will list the all the content databases for the selected webapplication as a link.When you click on the content database name navigation URL will be append as below.


So replace the %7B with Open curly brace ( { ),%2D with closed dash (-) and %7D with closed curly brace ({}.

Step 2

Fire the PowerShell Command to get the database Id

Get-SPContentDatabase -Identity wss_Content