Total Pageviews

27 Dec 2013

Get all Items from a list avoiding treshold

 private static List<SPListItem> GetAllListItems(SPWeb web, SPList list)
            List<SPListItem> listItems  = new List<SPListItem>();
            SPQuery query = new SPQuery();
            SPListItemCollection spListItems;
            string lastItemIdOnPage = null;
            int itemCount = 2000;

            while (itemCount == 2000)
                query.ViewFieldsOnly = false;
                query.RowLimit = 2000;
                if (lastItemIdOnPage != null)
                    SPListItemCollectionPosition pos = new SPListItemCollectionPosition(lastItemIdOnPage);
                    query.ListItemCollectionPosition = pos;
                spListItems = list.GetItems(query);

                if (spListItems.ListItemCollectionPosition == null)

                lastItemIdOnPage = spListItems.ListItemCollectionPosition.PagingInfo;
                itemCount = spListItems.Count;
            return listItems;

19 Dec 2013

List of Useful SharePoint CSS Classes

When developing custom SharePoint solutions you can save a lot of time by taking advantage of the built-in CSS classes inside corev4.css or  corev15.css files.

For instance: you can use ms-error class in order to make your label red.
You can also use these:
.s4-clust - hides the element for the print view.

Here is a good list of ready-to-use CSS classes:

Unfortunately, this link does not contain the whole list of useful classes, but it's a good start anyway.

13 Dec 2013

Change "SharePoint" in ms-core-brandingtext

In case you were wondering how to change "SharePoint" text in the top left corner:

In SharePoint Management PowerShell:

$app = get-spwebApplication "http://mysite"
$app.SuiteBarBrandingElementHtml = "<div class='ms-core-brandingText'>Custom Brand</div>"


6 Dec 2013

Setting up Exchange 2013 for SharePoint 2013 Development Environment. Outbound email

Begin with setting up Exchange Server Receive Connector:
    • Open Exchange admin center (https://localhost/ecp) site;
    • Mail flow --> receive connectors:
    • Select Default Frontend Connector and edit it

    • In security section, make sure "Anonymous users" are allowed:

You can test outgoing email via PowerShell with the following script:
Add-PSSnapin Microsoft.sharePoint.powershell
$Dictionary = new-object System.collections.specialized.stringdictionary
$Dictionary.add("Subject","Testing email")
$Web = get-spweb "http://localhost"
$Body = "Sending it from PowerShell"

If this script returns #True - it worked just fine.
If it returned "#False" - you will need to check SharePoint ULS in order to find what happened exactly.

Possible problem with while testing outgoing email: 451 4.7.0 Temporary server error. Please try again later. PRX2":
Solution: make sure you've got only one DNS for your network adapter on your Exchange Server. Make sure you are using address of your DNS server of your local domain. Do not include any other external DNS servers.

Here are others things to consider:
  1. Make sure that IPv6 is enabled on Exchange server. This is important when you are trying to connect Outlook to Exchange Server:
  2. Add host file entries on your SharePoint server that target Exchange server you receive "could not resolve domain name" error:
(SharePoint Server's hosts file)

After all pain - success!

20 Nov 2013

Create Virtual Machine with Preinstalled SharePoint 2010/2013 Development Environment.

Here are the steps you should follow in order to create a preinstalled environment on a virtual machine:

  1. Install Windows Server 2008 R2/Windows Server 2012
  2. Install SharePoint 2013/2010 with all updates and do not run SharePoint Configuration Wizard
  3. You can install Visual Studio
  4. You can install Microsoft Office
  5. Do not install SQL Server because it can't be sysprepped.
  6. Do not enter any domains. Just because it's useless and I haven't checked whether it works or not.
  7. run C:\Windows\System32\Sysprep\Sysprep.exe
    1. Make sure you've checked "Generalize" option:
  8. Backup your virtual machine for later reuse
After you run your virtual environment you will need to:
  1. Install Domain controller role if it's a standalone Development environment.
  2. Join a domain (in case of SharePoint 2013) 
  3. Install SQL Server (optional)
  4. Run SharePoint Configuration Wizard
There is only one mandatory step (Run SharePoint Configuration Wizard) you will need to do on your sysprepped virtual machine. Very convenient.

Installing SharePoint 2013 on Windows Server 2012 R2 RTM. Bad Idea so far.

Right, here is my warning: You really don't want to install SP 2013 on Windows Server 2012 R2. Install it on Windows Server 2012, Windows Server 2008 R2, but not on Windows Server 2012 R2. Mark my words. I've spent two last days struggling with a pile of problems installing and reinstalling OS, prerequisites, SQL, you name it.

  • SharePoint 2013 Prerequisites installer does not recognize Windows Server 2012 R2 as a supported OS
  • Mandatory SharePoint 2013 March Update takes ages to install. 
  • You'll have to download and install all prerequisites on your own. Good luck installing IIS Role and corresponding features correctly. 
  • During SharePoint Configuration Wizard I was receiving an ArgumentOutOfRange Exception when provisioning Central Administration Site. Nothing helped to resolve this one

I was using MSDN ISO images of Windows Server 2012 R2 and SharePoint Server 2013. I've just installed it on Windows Server 2008 R2 and received not a single error.

In case you really want to do it there is nothing better than these two articles:

If you need a SharePoint 2013 development environment better get Windows Server 2008 R2 or Windows Server 2012.

Looks like Office Web Apps 2013 Installer also has problems with Windows Server 2012 R2. It quits with an unknown error. Oh well..

16 Nov 2013

Debugging Native SharePoint DLLs with Reflector. "Cannot obtain value of local or argument as it is not available at this instruction pointer"

[original solution was found here]

This is a very reliable solution that helps me to inspect local variables while debugging OOB SharePoint DLL using Reflector:

1. Create a file with the following content:

[.NET Framework Debugging Control] 

2. Save it to the GAC, within each folder of dll you want to disable its optimization, and name it with the name of the dll, with the extension ".ini".

3. Success!

It seems that I've forgotten another important thing that has to be enabled.

1. Go to the registry and in the path HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\

2. Create a variable with a name COMPLUS_ZAPDISABLE and set it set it to 1:

9 Nov 2013

ShowField="NameWithPicture attribute breaks field rendering in SharePoint 2013

I've noticed that  ShowField="NameWithPicture" attribute  in SharePoint 2013 does not render properly:

So, instead of NameWithPicture value
<Field Name="Employee" ID="{33c2ee31-2927-4de3-8e7d-cc1f2676378b}" DisplayName="Сотрудник" Type="User" Required="TRUE" UserSelectionMode="PeopleOnly" UserSelectionScope="0" ShowField="NameWithPicture" /

you can use NameWithPictureAndDetails:
<Field Name="Employee" ID="{33c2ee31-2927-4de3-8e7d-cc1f2676378b}" DisplayName="Сотрудник" Type="User" Required="TRUE" UserSelectionMode="PeopleOnly" UserSelectionScope="0" ShowField="NameWithPictureAndDetails" />

The result should look simillar to:

I've also noticed, that you can also change the way user field is displayed. There is a number of ways this field can be rendered. Honestly, I had no idea you could do that!

Update (Solution #2):
Looks like after updating Visual Studio Projects from SP2010 to SP 2013 you can include <JSLink>clienttemplates.js</JSLink> node into your View in schema.xml:

This will allow you to render User field with  ShowField="NameWithPicture" properly.

How to Create a Site Collection Inside a Given Database without PowerShell?

  1. In Central Administration go to Manage content databases
  2. For each database set Maximum Number of Site Collections te be equal to Current Number of Site Collections. 
  3. Make sure your desired Database still didn't reach the limit of site collections number
  4. Create your new site collection as usual
  5. Return all Database settings back to where there were.

29 Aug 2013

Get features grouped by solution package

foreach ($grp in Get-SPFeature | Group-Object SolutionId) {
    $sol = Get-SPSolution -Identity $grp.Name
    Write-Host $sol.Name '(ID:' $grp.Name '), Count:' $grp.Count -ForegroundColor Blue
    foreach ($fd in $grp.Group | sort DisplayName ) {
        Write-Host $fd.DisplayName '(' $fd.Scope ')'

6 Aug 2013

System.Diagnostics.Debugger.Break() for debugging Features

In certain cases, there is no easy way to debug FeatureActivating or FeatureDeactivating methods either because there is no UI process to attach to or you are deploying the project from Visual Studio. For example, If you set a breakpoint inside the asynchronous FeatureActivating method - it will not hit during execution unless you are somehow attached to the correct process.

So, for debugging purposes, you can include System.Diagnostics.Debugger.Break();  inside the FeatureActivating method:

        public override void FeatureActivating(SPFeatureReceiverProperties properties)

             // Feature code...

At the time System.Diagnostics.Debugger.Break() is executed you System will show you a dialog box with an exception, prompting you to select a desired way to debug "a problem". It's not a problem of course :)  Then you have to select your Visual Studio SharePoint project which should be already open. After a few moments you will be redirected to the System.Diagnostics.Debugger.Break(); and you will see that your lovely breakpoint actually worked fine. Now you can go on and continue debugging.

Feature Stapling changes for MySites in SharePoint 2013

In case of My Sites, Elements.xml for the feature stapler you have to change TemplateName="SPSPERS#0"  to TemplateName="SPSPERS#2"

So, the resulting XML might look just like that:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
  <FeatureSiteTemplateAssociation Id="91a39059-e694-4c80-8341-e18db90c0c58"

5 Aug 2013

ULS, SharePoint Foundation Monitoring High Leaving Monitored Scope (EnsureListItemsData). Execution Time=XXX

Ever wondered what this message meant in ULS?

First of all, there is a public SPMonitoredScope class that allows us to discover  performance bottlenecks.
One of the implementations of this method looks like following:
public SPMonitoredScope(string name, uint maximumExecutionTime, params ISPScopedPerformanceMonitor[] monitors)

If maximumExecutionTime parameter is set to 250, a debug message will be written to ULS when a certain piece of code runs more than 250 milliseconds.

When SPList.GetItems method is executed you don't immediately get data from DataBase because this method is differed until the actual data is requested somewhere. So, when you try to debug performance bottlenecks you might find that this method executes pretty fast. However, when, later you try to request SPListItemCollection the internal EnsureListItemsData method is run. This exact method will ensure that the actual data is retrieved. This is where it might take quite some time to get your List items. Let's see at the internal implementation of the EnsureListItemsData method:

        protected void EnsureListItemsData()
                using (new SPMonitoredScope("EnsureListItemsData", 250, new ISPScopedPerformanceMonitor[] { new SPSqlQueryCounter(1) }))
                   // Code that fetches data from the Database

As you can see, maximumExecutionTime parameter is set to 250 milliseconds.When the process of getting List data from SPList gets longer that this time you will see this message:

ULS, SharePoint Foundation Monitoring  High Leaving Monitored Scope (EnsureListItemsData). Execution Time=XXX

I hope it sheds some light on this mysterious ULS message.

2 Aug 2013

ManagedLink Attribute for Web Part Properties that Converts Absolute URLs to Relative Ones

[ManagedLink] above the web part property automatically converts full Urls to relative ones. very useful for fool proofing against incorrectly typed URL's.
For example, http://portal/Lists/CustomList/Forms/Display.asxp becomes l/Lists/CustomList/Forms/Display.asxp

C# example:
        WebDisplayName("Friendly Display Name"),
        WebDescription("Values: Whatever value you need")]

        public Uri URI { get; set; }

Validate Web Part Properties using WebPartPageUserException

throw new WebPartPageUserException("OMG Something went wrong!");

Download and Install SharePoint 2013 Prerequisites on Windows Server 2012

These PowerShell scripts will automate downloading and installing the SharePoint 2013 Prerequisites on Windows Server 2012. The scripts will assist those who need to install SharePoint 2013 'offline' or wish to manually install its Prerequisites on Windows Server 2012.
Here is the link

Detect installed SharePoint 2010 or 2013 products using PowerShell

This PowerShell function returns a hash table to the pipeline containing SharePoint 2010 or 2013 products and the SharePoint Build Version installed on your server.
Here is the link.

26 Jul 2013

Allowing C# on Master Page and Layout Pages

1. Open web.config;
2. Find PageParserPaths node;
3. Add the following PageParserPath none so that it looks like so:
   <PageParserPath VirtualPath="/*" CompilationMode="Always" AllowServerSideScript="True" IncludeSubFolders="True" />

25 Jun 2013

Managed metadata navigation and friendly URLs in Sharepoint 2013

Here is one of the three very good articles on new Managed Metadata features in SP 2013

Failed to create term set: A default managed metadata service connection hasn't been specified.

Here is a problem that might occur when dealing with Managed Metadata Service when trying to set up a Taxonomy-based navigation:
To fix this problem go to Central Administration, select your Managed Metadata Service (the second one on the screenshot) and make sure "This service application is the defaul storage location for column specifit term sets" is selected:


SharePoint 2013 What's new with WCM

Enabling HTML5 on SharePoint 2010 Master Page

This is the original article.

The steps are:
  1. Open your custom Master Page replace the existing DOCTYPE tag with the following HTML5 doctype: <!DOCTYPE html>
  2. Now look for the meta tag, X-UA-Compatible, found in the head section. It should look like: <meta http-equiv="X-UA-Compatible" content="IE=8" />
  3. Update the “content” value to "IE=Edge" 
That's it! now you can use lots of CSS 3.0 and HTML5 features.

19 Jun 2013

Using SVG Images with Modernizr.js

If you need to add an SVG to your HTML page here what you should do:

  • Install Inkscape (it's free to use).
  • Create SVG file
  • Export to PNG. This file will be used as a fallback in older browsers like IE 7 and IE 8
  • Create HML page and add .svg Image on it. Problem: IE8 does not support SVG. That's why you need modernizr.js
  • Include modernizr.js to the page. This will add "svg" or "no-svg" classes to the <HTML> tag.
  • Now you can use ".no-svg" and ".svg" classes in you CSS selectors to provide fallback to PNG images. In other words, you need to load .png images only when  no-svg class exists in DOM. 
Final HTML and CSS should be like following:
.svg .star-box{
   height: 48px;
   width: 52px;
   background: url("woman.svg") ;
   background-size: 100% 100%;
}.no-svg .star-box
{   background: url("woman.png") no-repeat;
   height: 68px;
   width: 48px;
   min-width: 1024px;
   background-size: 100% 100%;

<div class="star-box"/>

So, when a browser supports SVG - .svg files will be used. If it does not it will fall back to using PNG.

14 Jun 2013

Changing SharePoint 2010 Favicion

In SharePoint Designer, open your current master page and change the following tag:
<SharePoint:SPShortcutIcon runat="server" IconUrl="/_layouts/images/yourFavicon/favicon.ico"/>

jQuery plugin for SharePoint 2010/2013 That turns on WYSIWYG Feature for Selected DIV Tags, Hack

Enable and disable native SharePoint WYSIWYG HTML Editor:

SharePoint 2010 Version:

 (function ($) {  
   $.fn.SPEditable = function () {  
     return this.each(function () {  
       $(this).addClass("ms-rtestate-write ms-rteflags-0 ms-rtestate-field").attr("role", "textbox").attr("aria-haspopup", "true").attr("style", "min-height: 84px;").attr("contentEditable", "true").attr("UseInlineStyle", "True").attr("aria-autocomplete", "both").attr("aria-multiline", "true");  
   $.fn.SPNonEditable = function () {  
     return this.each(function () {  
       $(this).removeClass("ms-rtestate-write ms-rteflags-0 ms-rtestate-field").removeAttr("role aria-haspopup style contentEditable UseInlineStyle aria-multiline");  


The result is amazing:
One thing to remember: this only works when you are in edit mode either in a list item or page.

An advanced example:

SharePoint 2013 version:

 (function ($) {  
   $.fn.SPEditable = function () {  
     return this.each(function () {  
       $(this).addClass("ms-rte-layoutszone-inner-editable ms-rtestate-write").attr("role", "textbox").attr("aria-haspopup", "true").attr("contentEditable", "true").attr("aria-autocomplete", "both").attr("aria-autocomplete", "both").attr("aria-multiline", "true");  
   $.fn.SPNonEditable = function () {  
     return this.each(function () {  
       $(this).removeClass("ms-rte-layoutszone-inner-editable ms-rtestate-write").removeAttr("role aria-haspopup contentEditable aria-autocomplete aria-multiline");  

Run Custom Function before "Save" Button is Clicked with PreSaveAction. SharePoint 2010

Add Javascript function to the page:

function PreSaveAction() 

    // your custom code goes here
    return true;  // OK to proceed with the save item }

For more information, check this post:

5 Jun 2013

Run C# Code from Powershell that uses SharePoint DLL's

Here is a very nice article

For example:

$Assem = ( 

"Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" , 

"Microsoft.SharePoint.Publishing, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" 


$Source = @" 

using Microsoft.SharePoint.Publishing.Administration; 

using System; 

namespace StefanG.Tools 


public static class CDRemoteTimeout 


public static void Get() 


ContentDeploymentConfiguration cdconfig = ContentDeploymentConfiguration.GetInstance(); 

Console.WriteLine("Remote Timeout: "+cdconfig.RemoteTimeout); 


public static void Set(int seconds) 


ContentDeploymentConfiguration cdconfig = ContentDeploymentConfiguration.GetInstance(); 

cdconfig.RemoteTimeout = seconds;






Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharp 



4 Jun 2013

SharePoint 2010. Open 'Browse' Ribbon Tab by Default

Just include InitialTabID=Ribbon.Read in your URL parameter:

29 May 2013

Detect Edit Mode with Javascript on SharePoint pages or SPListitem forms

This JavaScript function will tell you if we are in the List Edit form:

var isEditForm = function ()
    var sPath = window.location.pathname;
    var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
    if (sPage == "EditForm.aspx")
    return true;
    else return false;

And this one will tell you if we are in edit mode on publishing, web part or wiki pages
var isinEditMode = function() {
    var isEditMode = false;
    try {
        var inDesignMode = document.forms[window.MSOWebPartPageFormName].MSOLayout_InDesignMode.value;

        if (inDesignMode == "1") {
            isEditMode = true;

    } catch(e) {

    try {
        var wikiInEditMode = document.forms[window.MSOWebPartPageFormName]._wikiPageMode.value;
        if (wikiInEditMode == "Edit") {
            isEditMode = true;
    } catch(e) {


    return isEditMode;

14 May 2013

Applying custom page to all subsites

You've create a custom master page and want to apply it to all of your subsites. Use this link to do just that:


Warning: Publishing Infrastructure Feature must be enabled on your site collection.

28 Apr 2013

SharePoint 2013. New JSLink property for SPField

This is a side note about the use of JSLink property in SPFields. I intend to use this later in my projects. Here are 2 simple steps.

1.Create and deploy JS Field with the script that looks like this:

2. Change the new JSLink property for you SPField like is show on the screenshot. Note that it may be even built-in field.

The result should look like this. I've added a simple "refresh" image inside the field as a test.

For more info you could check this nice article SP 2013: Using the JSLink property to change the way your field or views are rendered in SharePoint 2013

4 Apr 2013

Highlight Current Quick Launch Menu Item

1. Add a start-up script on your page
$(function () {
    $(".s4-ql li.selected").parents("li.static").find(":first-child").first().addClass("selected-menu-item");

2. Take advantage of the added CSS class to highlight current menu item:

.s4-ql UL.root a.selected-menu-item {
    background-color: rgb(0,153,0);

Example of the highlighted menu item:

3 Apr 2013

SharePoint 2010 CSS Chart

On on the Marc's SharePoint Notes I've found a very informative table that looks like this:

.ms-cui-cg-gr .ms-cui-tt-a:hover{





For the full table check the link above.

It's pretty self-explanatory, I think.

21 Feb 2013

Testing Mobile View in Chrome

1. In Chrome, open the Developer Tools  by clicking "Customize"(wrench icon) --> "Tools" --> "Developer Tools."

2. Click the "Settings" icon at the botom right corner.
3. Check "override user agent" and select one of the options (iPhone, iPad or Nexus S running Android 2.3). You can also select "other" and enter a custom user agent.

The result looks like that:

20 Feb 2013

Stopping Credentials Dialog from Popping Up

  • Add your sire to Local Intranet to stop it from asking for credentials. Note that if your site is in Trusted zone and not in Local Intranet it will still ask you to provide a password!
  • Add your  site to Trusted Zone to stop pop-up window from appearing when opening MS office documents from lybraries. It will actually stop DispEx Function from running when clicking on the document

Conclusion: add your SharePoint site either to Local Intranet or Trusted zone.

DispEx Function does not run

Moving the site to trusted sites stops the JavaScript function DispEx from running.

12 Feb 2013

SharePoint Designer 2010 – The server could not complete your request. The content type of the response is

This is mostly happening due to the use of SPConfigModification.

1. Open web.config
2. Search for section <system.serviceModel>
3. add the following tag to the section:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
4. done!

Original solution was found here


11 Feb 2013

What is a SharePoint Administrator?

I've encountered an interesting question on Stack Exchange: "What is the (estimated) administration cost for a SharePoint-Farm?".

To answer this question it's important first to define the scope of tasks SharePoint Administrator is responsible for. Here is a good article describing just that:
What is a SharePoint Administrator?

6 Feb 2013

Opening Modal Dialog on Custom Action

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="">
                Description="Create Dialog With Scenario"
                Rights="AddListItems" Title="Create Dialog">
  <UrlAction Url="javascript:OpenPopUpPageWithTitle('/_layouts/CustomSPCF/customspcf.aspx', RefreshOnDialogClose, 640, 610,'Create Dialog')"/>

11 Jan 2013

Testing SharePoint Server Search with KeywordQuery

   class Program
        static void Main(string[] args)

            SearchQueryAndSiteSettingsServiceProxy settingsProxy = SPFarm.Local.ServiceProxies.GetValue<SearchQueryAndSiteSettingsServiceProxy>();

            SearchServiceApplicationProxy searchProxy = settingsProxy.ApplicationProxies.GetValue<SearchServiceApplicationProxy>("Enterprise Search Service");

            KeywordQuery keywordQuery = new KeywordQuery(searchProxy);

            keywordQuery.QueryText = "Region:b2a48ce5-31e0-40f7-873b-f4fbceacc45f";


            //The creator of this fault did not specify a Reason:
           // keywordQuery.SelectProperties.Add("owsMetadataFacetInfo");
           // keywordQuery.SelectProperties.Add("owstaxIdRegion");

            keywordQuery.ResultsProvider = SearchProvider.Default;

            keywordQuery.ResultTypes = ResultType.RelevantResults;

            keywordQuery.RowLimit = 50;

            ResultTableCollection resultsTableCollection = keywordQuery.Execute();

            ResultTable searchResultsTable = resultsTableCollection[ResultType.RelevantResults];

            DataTable resultsDataTable = new DataTable();

            resultsDataTable.TableName = "Results";

            resultsDataTable.Load(searchResultsTable, LoadOption.OverwriteChanges);


            for (int j = 0; j < resultsDataTable.Rows.Count; j++)

                DataRow row = resultsDataTable.Rows[j];
                foreach (DataColumn column in resultsDataTable.Columns)
                    Console.Write("Item: ");
                    Console.Write(" ");

     using(SPSite site = new SPSite(""))
                SearchServiceApplicationProxy ssa = (SearchServiceApplicationProxy)SearchServiceApplicationProxy.GetProxy(SPServiceContext.GetContext(site));

                KeywordQuery kq = new KeywordQuery(ssa);
                kq.ResultsProvider = SearchProvider.Default;
                kq.QueryText = string.Format(CultureInfo.InvariantCulture, "scope:\"{0}\"; title:\"Ivanov Ivan\"", "people");
                kq.ResultTypes = ResultType.RelevantResults;
                kq.StartRow = 0;
                kq.EnablePhonetic = true;
                kq.EnableStemming = true;
                kq.RowLimit = 1000;
                kq.KeywordInclusion = KeywordInclusion.AllKeywords;

                ResultTableCollection res = kq.Execute();

                bool exists = res.Exists(ResultType.RelevantResults);

                if (exists)
                    ResultTable searchResult = res[ResultType.RelevantResults];


How to configure Incoming Email Enabled Libraries in MOSS2007 RTM using Exchange 2007 in an Active Directory Domain

Check this out :)

Adding a warm-up step to your SharePoint project deploy action

I've recently found a very useful blog post on how to improve SharePoint Deployment experience in Visual Studio.

Check this out!

Simple Custom Error Page

  1. In web.config set: 
    •  CallStack="false" 
    •  customErrors mode="On"
  2. Run Powershell command "Set-SPCustomLayoutsPage -Identity Error -RelativePath /_layouts/CustomError/error.aspx -WebApplication http://Srv
  3. Add a new ASPX page to /_layouts/CustomError/error.aspx: 
You can download source code from here. My custom error page looks like that:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<%@ Import Namespace="Microsoft.SharePoint.Administration"  %>
<html xmlns="">
<script language="C#" runat="server">

    public void Page_Load(object sender, EventArgs e)
        StringBuilder sb = new StringBuilder();
        sb.Append("Error occured:");

        Exception[] errors = Context.AllErrors;

        if (errors == null)

        for (int i = 0; i < errors.Length; i++)
            Exception err = errors[i];


            if (err.InnerException != null && err.InnerException.Message != err.Message)
                sb.Append("<br><br>" + err.InnerException.Message);

        lblError.Text = sb.ToString();        

    private static void LogError(string message)
        uint customId = 7777;
            new SPDiagnosticsCategory("CustomError Message", TraceSeverity.Unexpected, EventSeverity.Error),
            TraceSeverity.Unexpected, message);


<asp:Label ID="lblError" runat="server" />