Friday, October 26, 2012

The Module SharePoint Project Item type


The SharePoint Developer Tools provide a SharePoint Project Item Type named Module, which
provides a layer of productivity on top of the CAML-based Module element. You can add a
new Module SharePoint Project Item Type to a SharePoint project using the Add New Item
dialog of Visual Studio 2010.

Add New Item SharePoint 2010

In addition to provisioning objects within the top-level site, activation of the
MainSite feature creates a simple navigation scheme by adding four links to the top link bar.
This is accomplished in the FeatureActivated method by using the server-side object model
to add four new SPNavigationNode objects to the TopNavigationBar property of the current
SPWeb object’s Navigation property.

public override void FeatureActivated(SPFeatureReceiverProperties properties)
            SPSite oSPSite = new SPSite("http://amit-pc");
            //Open Sharepoint Site
            SPWeb oSPWeb = oSPSite.OpenWeb();
            oSPWeb.AllowUnsafeUpdates = true;

            // create menu for custom site pages
            SPNavigationNodeCollection topNav = oSPWeb.Navigation.TopNavigationBar;
            topNav.AddAsLast(new SPNavigationNode("Page 1", "Module1/Sample.txt"));
            topNav.AddAsLast(new SPNavigationNode("Page 2", "Module1/Sample.txt"));
            topNav.AddAsLast(new SPNavigationNode("Page 3", "Module1/Sample.txt"));
            topNav.AddAsLast(new SPNavigationNode("Page 4", "Module1/Sample.txt"));

using the above given code we can get the navigation in the site as shown in the below given figure:

SharePoint 2010

Thursday, October 25, 2012

SharePoint Master Pages

I believe that you all might be aware of the concept of Master Pages in .NET and SharePoint 2007. The obvious benefit of Master pages is that all the pages in a SharePoint site can link to a single Master Page to achieve a consistent look and feel.

Enhancements were made in SharePoint 2010 so that single master page can be used with both Site Pages and Application Pages.

Whenever SharePoint foundation provisions a new site, it creates a special hidden document library known as Master Page Gallery; and creates three new Master Page instances:

  • v4.Master
  • minimal.master
  • default.master

v4.Master: This is the primary master page used in SharePoint 2010 sites. Ex: Team Site Master page. It includes element such as Site Actions menu, the breadcrumb trail, the Ribbon, the welcome menu, the site icon, the topNav bar and the quick launch.

minimal.master: minimal.master is a page layout without any of the chrome that is included in v4.master.

default.master: default.master is a master page designed to support a feature known as visual upgrade, which assists in upgrading SharePoint 2007 sites to run within SharePoint 2010 farms.

Differentiating between Site Pages and Application Pages


Whenever you need to design SharePoint Solutions you will find the requirement for creating pages to a site. Therefore you must be knowing the fundamental difference between Site Pages and Application Pages so that you can decide which one to use and when. Therefore in this post I am trying to summarize the difference between the two.

Advantages Site Pages
Site Pages support customization through the browser and with SharePoint designer 2010. Example of Site Pages is NewForm.aspx, AllItems.aspx, EditForm.aspx.

Disadvantages Site Pages
Site Pages require elaborate processing infrastructure that has implications on security, performance and scalability. Also the Site Pages run in Safe Mode and hence its not possible to write inline code. Each customized page instance must be loaded separately into memory.

Advantages Application Pages
Application pages do not support customization, this gives them a few distinctive advantage over Site Pages:

  • First, they can be used in scenarios where we don’t want to give the control to user to edit the page.
  • Second, they do not run in safe mode and hence inline coding is possible
  • Third, each Application page is compiled into a single assembly DLL, this makes it perform better and scalable then site pages that can be customized.

Disadvantages Application Pages
Application pages are deployed inside the SharePoint root directory, which means that they cannot be used in Sandbox Solution.

Saturday, October 20, 2012

Convert Text to HTML in SharePoint

Recently I was working on task in which I need to display some HTML content by using a Calculated Column. Then I found a script/ JavaScript which actually converts the text written in calculated column into HTML. So in this blog I'll be stating that JavaScript using which you can use to achieve the desired results.

<script type="text/javascript">
function TextToHTML(NodeSet, HTMLregexp) {
var CellContent = "";
var i=0;
while (i < NodeSet.length){
try {
CellContent = NodeSet[i].innerText || NodeSet[i].textContent;
if (HTMLregexp.test(CellContent)) {NodeSet[i].innerHTML = CellContent;}

// Calendar views
var regexpA = new RegExp("\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*");

// List views
var regexpTD = new RegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");

// This function is call continuesly every 100ms until the length of the main field changes
// after which the convert text to HTML is executed.
var postElemLength = 0;
function PostConvertToHtml()
     if (postElemLength == document.getElementsByTagName("TD").length)
          var regexpTD = new RegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");

// Grouped list views
ExpGroupRenderData = (function (old) {
    return function (htmlToRender, groupName, isLoaded) {

    var result = old(htmlToRender, groupName, isLoaded);
    var regexpTD = new RegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");

    // start the periodic callback to check when the element has been changed
    if(isLoaded == 'false')
        postElemLength = document.getElementsByTagName("TD").length;

// Preview pane views
if (typeof(showpreview1)=="function") {
showpreview1 = (function (old) {
    return function (o) {
    var result = old(o);
    var regexpTD = new RegExp("^\\s*<([a-zA-Z]*)(.|\\s)*/\\1?>\\s*$");

Add Custom menu Item in ECB Menu using Javascript

Why to go for Visual Studio and customizing solutions when most of the tasks can be performed using the content editor web part, jQuery and JavaScript. I have been looking for a solution to add a custom menu item in ECB, but all the solutions I got were directed towards designing the solution using Visual Studio. But here is a very simple solution in which you can add this below given code in a  CEWP (Content Editor Web Part).

<script language="javascript">
function Custom_AddListMenuItems(m, ctx)
var strDisplayText = "Add Update";
var strAction = "STSNavigate('"+ctx.listUrlDir+"/EditForm.aspx?ID=" + currentItemID  + "')";
var strImagePath = ctx.imagesPath+"edititem.gif";
// Add our new menu item
CAMOpt(m, strDisplayText, strAction, strImagePath);
// add a separator to the menu
// false means that the standard menu items should also be rendered
return false;

Try it !!!! ;)

Friday, October 19, 2012

Hide Ribbon Controls

Hi Guys,

Yesterday I was working on an application in MS SharePoint 2010 and there I come up with a task where I had to hide "New Item" and "Edit Item" Controls from the SharePoint Ribbon Menu. To do so we need to embed the below given code in the 'Content Editor Web Part'.

Given are the following steps that may help us in hiding the Add Item and Edit Item controls.

Edit SharePoint Page on which you need to hide the controls for that goto Site Actions >> Edit Page. This will open the page in the Edit mode where you need to add a web part by Clicking 'Add a Web Part'. Then from the categories select 'Media and Content' and from the sub-categories of Web Parts select 'Content Editor'

Content Editor Web Part
Media and Content >> Content Editor Web Part

After adding the Content Editor Web Part you need to edit the HTML Source as being shown in the below given screen print.

Edit Content Editor Web Part
Edit HTML Source of Content Editor Web Part

This will open a new window in which you need to paste the below given JavaScript.

<style type="text/css">

<style type="text/css">

I believe the above given post can help you too to Hide the Add Item and Edit Item Menu from the Ribbon Control. I am sure that this may work for you but if still you face any issue then you can drop me an email with the issue you are getting at mail@amitmathur[dot]in.

Thursday, October 18, 2012

Understanding Sandbox Solutions

Whenever a solution is to be deployed in a partially trusted environment it’s being deployed as a sandbox solution. This helps in providing a stable SharePoint farm by restricting actions that can cause problems with performance, security and other areas. This stability is achieved by restricting the custom solutions on the basis of Custom Access Security (CAS) policy and by restricting the access some portions of the object model.

Therefore it’s always being recommended to the developers to deploy and test the solution in a Sandbox Environment before deploying the same in the farm solution.

Enabling the use of Sandbox solution requires enabling the User Code Service in windows environment. This service can be enabled by logging on to the Central Administration >> System Settings >> Manage Services on Server.

Whenever the Sandbox Solution property is set to true, selecting Build/ Deploy Solution deploys the solution to the Site Collection Solution Gallery.

There is a terminology difference between Sandbox and Farm Solution and i.e. Farm Solutions are installed and deployed while Sandbox Solution are uploaded and activated. Activation of any Sandbox Solution automatically activates any feature scoped to the level of Site Collection.

Sandbox Solution can be deployed by the Site Collection Administrator and hence doesn’t require Farm Administrator like in the case of Farm Deployment.

Another feature that Sandbox Solution provides is that the solution can be upgraded whenever we upload a new version the system detects on the basis of id that a previous solution is uploaded with some upgrades and hence uninstall the previous version and installs the updated version on the same solution.



Although the User Code Service is responsible for managing the Solution Solutions; The Execution Manager, The Worker Service, and the Worker Service Proxy is also responsible for managing the solutions as being shown in the below given diagram:

Sandbox Solution Architecture

Execution Manager handles the load and execution of the Sandbox Solution Code. Execution Manager works in the IIS Application pool and is responsible for calling User Code Service (SPUCHostService.exe) requesting that a sandbox solution is loaded.

The user code service makes a request to the worker process (SPUCWorkerProcess.exe) to load the sandbox solution

Although the worker service utilizes the same framework as other services in the SharePoint farm it cannot make a direct connection to the Worker Service Proxy. Instead you simply configure the User Code Service for a Server.

Once the assembly of a Sandbox Solution is loaded into the Worker Service, its code can be executed. A pool of application domains is maintained within SPUCWorkerProcess.exe, and an available AppDomain is used to execute the request. Only one request at a time is executed in any AppDomain, so there won’t be conflicts between the solutions.

Sandbox System components are found in the 14 hive which is SharePoint System Directory:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\UserCode.

Here you can find SPUCHostService.exe, SPUCWorkerProcess.exe, and SPUCWorkerProcessProxy.exe. Along with the executables, you’ll also find a web.config file that references the CAS policy restrictions in the file C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\wss_usercode.config. Finally, this folderalso contains a subfolder named \Assemblies. The Assemblies folder contains the assemblies Microsoft.SharePoint.dll, Microsoft.SharePoint.SubsetProxy.dll, and Microsoft.SharePoint. UserCode.dll, which support the object model subset and creation of full-trust proxies.

Wednesday, October 10, 2012

Hello my Dear World!!!!


Hi Guys! This is my first Blog post and in this I wish to let you know that this post is being created for a basic introduction of mine and to let you know that I am here generally to help myself and to update my technical skills.  This is the best way to create a SharePoint Repository where I can assemble my tasks/ solutions in which I might had faced problem.  Another purpose of introducing this blog publically is to help the user across the globe to do their best in SharePoint. I am here with a purpose to resolve all the issues/ queries where you might had been stuck and is looking out for a solutions and I believe you can find in here. If unfortunately you are not able to get anything then you can drop me an email on ‘’ so that I can help/ assist you in getting the solution of the same.

Anyway I believe this is what I want to achieve and hope you all will going to help me in making this blog a success.

Love you all!
Happy reading!

- Amit Mathur