Blog of Sundar Narasiman

Microsoft MVP 2012

Year 2012 is off to a great start. Received my MVP renewal.

Congratulations! We are pleased to present you with the 2012 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in SharePoint Server technical communities during the past year.


Technical Review for MSDN articles

I had a chance to perform technical review for the following 12 MSDN articles. It gives a good satisfaction, when the reviewed articles are published.

Upload large documents to SharePoint site using WebClient class

One of the best way to programmatically upload large documents to SharePoint site is by leveraging the UploadAsync method of WebClient class. The WebClient class internally uses the WebDav protocol. This approach can be used for uploading documents to SharePoint Online (Office 365) as well. The only limitation with this approach is that we’ll not able to set the meta-data of the documents using WebClient class. Here is the code-snippet for the same:-

 WebClient oWebClient = new WebClient();

oWebClient.UseDefaultCredentials = true;
byte[] bFile = System.IO.File.ReadAllBytes(@"C:SundarWEB315.wmv");
string ulr = @"http://lt010593/Shared Documents/WEB315.wmv";
System.Uri oUri = new System.Uri(ulr);

oWebClient.UploadDataAsync(oUri, "PUT", bFile);
oWebClient.UploadDataCompleted += new UploadDataCompletedEventHandler(oWebClient_UploadDataCompleted);

 Subscribe to my blog

SPWebService.ContentService returning System.NullReferenceException

When I tried to access SPWebService.ContentService in the following code-snippet (executed inside a console application), I was getting Null value.

 SPWebService contentService = SPWebService.ContentService;
            contentService.ClientRequestServiceSettings.MaxReceivedMessageSize = -1;

            SPWcfServiceSettings csomWcfSettings = new SPWcfServiceSettings();
            csomWcfSettings.MaxReceivedMessageSize = 104857600; // 100MB
            contentService.WcfServiceSettings["client.svc"] = csomWcfSettings;


The resolution is to change the target CPU type in the Build properties from X86 to X64 or AnyCPu Type. That fixed my issue.

Programmatically add attachments to custom list using SharePoint 2010 Client Object Model

One of the important capability of SharePoint 2010 Managed Client Object model it its ability to add attachments to custom list. This capability is provided by the Microsoft.SharePoint.Client.File class in the client side APIs. The whole idea is to directly invoke the SaveBinaryDirect method of the Microsoft.SharePoint.Client.File class and pass the parameters like ClientContext, attachment path, filestream object and a boolean flag to set the overwrite status.

  using (ClientContext clientContext = new ClientContext("http://yoursitecollection"))

                Web oWeb = clientContext.Web;
                List oList = oWeb.Lists.GetByTitle("NewCustomList");               
                FileStream oFileStream = new FileStream(@"C:SundarTestFile.txt",FileMode.Open);
                string attachmentpath = "/Lists/NewCustomList/Attachments/2/TestFile.txt";
                Microsoft.SharePoint.Client.File.SaveBinaryDirect(clientContext, attachmentpath, oFileStream, true);             


The important point to consider here is how to frame the attachment path url for adding attachment. The attachment url needs to be in the following format :-


NameoftheList – is the name of the custom list where you want you add attachments

ItemNumber – is the id of the custom list item

AttachmentFile.extension – is the file to be attached

 Subscribe to my blog

Programmatically upload documents using SharePoint 2010 Client Object Model

The following code snippet helps us to programmatically upload documents to document library, using Client Object Model.

 using (ClientContext clientContext = new ClientContext("http://yoursitecollection"))

                Web oWeb = clientContext.Web;
                List oList = oWeb.Lists.GetByTitle("Shared Documents");               

                FileCreationInformation oFileCreationInformation = new FileCreationInformation();                  
                byte[] filecontent=System.IO.File.ReadAllBytes(@"C:SundarTestFile.txt");
                oFileCreationInformation.Content = filecontent;
                oFileCreationInformation.Url = @"http://yoursitecollection/Shared Documents/TestFile.txt";              



 Subscribe to my blog

Enabling Code Coverage for SharePoint 2010 Automated Unit Tests

I was wondering how to enable code-coverage for SharePoint 2010 automated unit test projects in Visual Studio 2010. Here are the steps :-

1. Double click on Local.testsettings


2. Go to Data and Diagnostics


3. Choose the list of assemblies to be instrumented


Locate the assembly file (.exe, .dll, or .ocx) that you want to include in code coverage and then click Open. The file is added to the list

4. If the source assemblies (to be instrumented) have a strong name, we need to re-sign those assemblies. Create a new key file that can be used for resigning assemblies. More details about the re-signing of assemblies can be found in this article .

Run the required unit tests for SharePoint code, now you will get an option to view code-coverage.

 Subscribe to my blog

Common symptoms of non-performing SharePoint code

The following are the common symptoms of a non-performing SharePoint code.

1. Frequent IIS Application Pool Recycling during the peak usage of the portal

The general practice is to allocate the IIS Application Pool Memory between 800MB – 1.5GB, assuming that at least 4GB RAM is available on the machine. The IIS App Pool recycle setting limit plays an important part in the recycling of app pool memory. The idea is that app pool re-cycle settings should not be too high or too low. The recommended app pool reset limit is 1 GB. Even after all this, the IIS App Pool resets frequently, then it has to be with SharePoint code. Make sure that the native SharePoint objects are disposed explicitly.

2. Poor Application Performance

Another symptom of a non-performing SharePoint code is the Poor Application performance. Meaning, during the peak load (when the memory usage increases), system would struggle to do paging and memory fragmentation, to compensate the load.

3. High Memory Usage for IIS Worker Process Memory

When the memory usage increases, the application would struggle to handle memory allocation. In many cases, this leads to “Out of Memory” exception, which leads to application crash, when unhandled in the code.

4. High Memory Usage for SQL

The common symptom of a non-performing SharePoint application is the high memory usage for SQL Process, when the system usage is not high. If the above symptoms persist, even after proper memory management in the code, then the Capacity Planning needs & sizing needs to be re-visited again.

 Subscribe to my blog

Installing SharePoint Foundation 2010 on Windows 7

One of the major improvement of SharePoint 2010 product is its ability to install and run on the client operating system like Windows 7. This article would elaborate the steps to install SP  Foundation 2010 on Windows 7 (X64). The configuration of my laptop is Intel I5 Processor, 4GB RAM and set up with Windows 7 Enterprise Edition (X64) & Visual studio 2010 Service Pack1.


Step1 –

Install WCF hotfix for Windows 7 located in


Install ADO.NET Data Services updates for .NET 3.5 SP1 located in


The next step is to install the other additional pre-requisites. The pre-requisite installer cannot be leveraged while installing SP Foundation 2010, unlike the installation of SP Server 2010. So the following pre-requisites have to be manually installed.


a) Microsoft Sync Framework

b) SQL Server Native Client

c) Windows Identity Foundation


Step 4

Enable the set of required Windows Features by running the following scripts

start /w pkgmgr /iu:IIS-WebServerRole;IIS-WebServer;IIS-CommonHttpFeatures;^


Step 5

The next task is to extract the SharePoint Foundation installer (SharePointFoundation.exe), apply required attributes for the configuration file.

Copy the SharePointFoundation.exe in to the folder where you want to install.

Extract the installer by typing the following in the command prompt
c:YourFolderSharePoint /extract:c:YourFolder


Open the Config.xml located in c:YourFolderfilesSetupconfig.xml

Add the following snippet inside <configuration> tag
<Setting Id="AllowWindowsClientInstall" Value="True"/>

Please make sure the the installer (SharePointFoundation.exe) is extracted only using the Extract option in Command prompt. If it is extracted using Winzip, it will given an error like “The language of this installation package is not supported”

Run SharePointFoundation.exe and install it as ‘StandAlone’







Run the SharePoint Configuration Wizard. If you are doing a standalone setup of SP Foundation2010, there is no need to install Microsoft SQL Server 2008 KB 970315 x64  hotfix.

Now it’s all set the SP Foundation 2010 setup is complete.

Microsoft Community Contributor Award 2011

Today I received a surprise mail from Microsoft saying that I’ve been recognized as Microsoft Community Contributor for the year 2011.  It is happy that my MSDN forum contributions towards SharePoint 2010 Development are recognized.


Congratulations! We’re pleased to inform you that your contributions to Microsoft online technical communities have been recognized with the Microsoft Community Contributor Award.
The Microsoft Community Contributor Award is reserved for participants who have made notable contributions in Microsoft online community forums such as TechNet, MSDN and Answers. The value of these resources is greatly enhanced by participants like you, who voluntarily contribute your time and energy to improve the online community experience for others.
Becoming a Microsoft Community Contributor Award recipient includes access to important benefits, such as complimentary resources to support you in your commitment to Microsoft online communities. To find out more about the Microsoft Community Contributor Award and to claim your recognition, please visit this site:


Microsoft has introduced Community Contributor Award program to say thanks to individuals who freely volunteer their time and energy to powering up and improve Microsoft online technical community experience for others. Microsoft Community Contributor Award Program is designed to recognize exceptional contributions to Microsoft online community forums such as TechNet, MSDN, and Answers.

Recipients of the Microsoft Community Contributor Award receive a small benefit which can serve as a resource for their participation in technical forums based on past year contributions and last for a year from the date of the award.

How does Microsoft select recipients of the Microsoft Community Contributor Award?
More and more technology users are seeking ideas and solutions for enhancing their technology experience through online resources. Microsoft reviews the contributions of participants who offer their time and energy to online technical communities such as Answers, MSDN and TechNet to identify those who make notable contributions for possible recognition as a Microsoft Community Contributor. In addition, Microsoft Community Contributors can be recommended by Microsoft Most Valuable Professionals, who serve as deep technical experts and thought leaders in the community.

There is no special requirement for the award program except you must be 18 years or older. For additional information about the Microsoft Community Contributor Award Program can be found at