Chris’s SharePoint Reflections

Just another weblog

  • Chris Zhong

    IT consultant Australia

Archive for the ‘development’ Category

Tips for SharePoint 2010 developers

Posted by chrissyz on June 25, 2011

Have you been developing SharePoint 2010 solutions? Here are a couple of tips I would like to share with you.

1. Integrate SPDisposal Checker into your Visual Studio development project

If you have been following my previous blog on disposing SPSite and SPWeb, you should already been familiar with the SPDisposal checker tool. To increase the development efficiency and team collaboration, I normally integrate the output into VS project so I can see the results everytime I build the assembilies. This is very useful on the team project to increase the code quality. The latest version has a Visual Stuido AddIn Option, which integrate the tool into your Visual Studio automatically and output the findings as Error/Warning. Highly recommend!

SPDisposal Checker for Visual Studio

2. SharePoint 2010 Developer Dashbroad

This tool is really good with troubleshooting. It gives us metrics and allows us to trace page load activities. I usually set it ondemand using stsadm command. Of course you can use Powershell as well. I know I am a bit old fashioned. 🙂

After then you should see a nice toggle button on the top right corner of the page. If  not, make sure you have the right permission to the site.

Posted in development, SharePoint 2010 | Tagged: , | Leave a Comment »

Dispose SPWeb/SPSite in MOSS/WSS

Posted by chrissyz on January 16, 2010

Why we need to dispose them?
In SharePoint, each SPWeb and SPSite object holds a reference to an SPRequest object which holds reference to a SharePoint COM object. In order to ensure that the SPRequest object will release the COM object as well as all the memory allocated by this COM object, it is necessary to dispose the unmanaged resources in a timely fashion. Though internally, .NET framework has a finalizer to release the native memory, however, as it runs on a single thread, it generally cannot keep up with cleaning these objects if they are being leaked many times in a second.
The consequence of not explicitly disposing unmanaged resources in a timely fashion can lead to not having enough memory and quickly consume memory. Furthermore, as each COM object is responsible to communicate with the backend SQL Server, in case the SPWeb object is not disposed when it is no longer used, then the connection to the SQL Server will stay open. Each connection to the database requires a TCP port for the communication. By default, only 5000-1023=3977 ports are available ( MaxUserPort Registry), which means on a single machine per default you cannot have more than 3977 open connections to other applications. So, besides the fact that not disposing SPWeb and SPSite will lead to higher memory consumption which finally can lead to out of the memory exceptions, the machine might also run out of TCP ports.

Symptoms/Issues which users can experience when the unmanaged objects are not disposed correctly
1. Database Connectivity
When object are not disposed correctly, you can find a lot of the following database related error messages in your SharePoint WFE event log and ULS log.
When all the TCP ports are in use, this will result in the following error message/event logs
• Event ID 3355 errors: Cannot connect to SQL Server. XXX not found. Additional error information from SQL Server is included below. [DBNETLIB][ConnectionOpen(Connection())]SQL Server does not exist or access denied.
• Event ID 27745 errors: Unable to connect to the database XXX. Check the database connection and make sure that the database server is running
• The ULS log shows the same database related error as above

2. ULS Logs errors
The ULS log will show errors when objects are not disposed correctly. The database related ULS log errors are already written down in the previous section. This section will focus on the SPDispose related error message in the ULS logs (by default located in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\LOGS). The error message will be like this

1/14/2010 14:15:48.91 w3wp.exe (0x145C) 0x04AC Windows SharePoint Services General 8l1n High An SPRequest object was not disposed before the end of this thread. To avoid wasting system resources, dispose of this object or its parent (such as an SPSite or SPWeb) as soon as you are done using it. This object will now be disposed. Allocation Id: {951F9932-6C3F-4FC9-AFA8-824892FA8142} To determine where this object was allocated, create a registry key at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\HeapSettings. Then create a new DWORD named SPRequestStackTrace with the value 1 under this key

Best Practices:
1. Practice the best coding practice regarding dispose the SPWeb/SPSite. Some good resources can be found on the internet.

2. SPDispose Checker Tool
On MSDN a tool is available which can check your developed assemblies. This tool will check most of the common dispose issues, but will not check all issues that can occur related to disposal of SharePoint objects. So you should fix at least all issues which are found after running the SPDispose Checker and then continue applying the best coding practices

3. Be aware of the out-of –the-box memory hungry component
Be aware of some of the OOTB components can require huge amount of memory when incorrectly configured. Navigation control is a good example. For each item in a navigation control that has to be retrieved through the sharepoint site map provider SPWeb and SPSite will have to be created. Though the control itself ensure that those objects are disposed correctly before the request ends there are often several of these objects in parallel in memory while the control is being rendered.
4. Switching to 64-bit architecture
In 64-bit architecture, the virtual address space is no longer limited to 2GB. This also means that memory fragmentation will not have the negative effects as in 32-bit architecture. However, even in 64-bit architecture, you still have the same limitation regarding TCP ports.

Posted in development, Performance | 1 Comment »

SharePoint DateTime Control

Posted by chrissyz on July 9, 2009

SharePoint brings its own controls and DateTime control is one of them. You can definitely leverage it in your web parts and custom aspx pages. The control is located in the Microsoft.SharePoint.WebControls namespaces.

How to define it? First you need to add the following directive at the top of your application page:

<%@ Register TagPrefix=”SharePoint” Namespace=”Microsoft.SharePoint.WebControls” Assembly=”Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c” %>

And then place the control in your page

<SharePoint:DateTimeControl runat=”server ID=”dtcDateTime”/>

Please notes that above is just a basic definition, for detailed properties, please check out this link:

How to validate it?

<SharePoint:DateTimeControl runat=”server ID=”dtcDateTime”/>

<asp:CompareValidator ID=”valDateTime” runat=”server”

ErrorMessage=”please enter a valid date” />

How to set a default value to it?
dtcDateTime.SelectedDate = new DateTime();
Check this link for the overloads:

Important notice:

There is a Microsoft bug in SharePoint DateTime Control.
This DateTimeControl loses state during postbacks, specifically of the hour.
I struggled a bit to get this work around because it doesn’t work even if I put enableviewstate=”true” in the control.
However I happened to get this work by adding this line of code in a event that caused the postback. It could be any method/Event, in my case, it is SelectedIndexChanged event:
if (dtcDateTime< DateTime.Today)
//Don’t do anything
Just be doing this, it maintains the value of the control during postback.

Posted in development | Tagged: | 9 Comments »

Customization of SharePoint list menu item – Part 1 add Custom Action Item

Posted by chrissyz on June 6, 2009

It has been a while since last time I blogged. And I do feel bad about being ignorant of my blog for such a long time. So this time I am gonna show some code to feed those hungry souls. Today I would like to talk about adding a list menu item through feature. This example is to add a menu item in a calendar list.

We all know a feature includes two files, feature.xml and elements.xml

In our feature.xml, nothing special, it will look like any other normal

<?xml version=1.0encoding=utf-8?>

<Feature  Id=GUID”
          Title=Calender list Menu
          Description=Creates Custom Action in Calender list item menu”


<ElementManifest Location=elements.xml/>



Then comes the elements.xml

<?xml version=1.0encoding=utf-8?>

<Elements xmlns=>

    Title=Calendar Custom Action>


RegistrationType can be “ContentType”, “FileType” (for example if you only want your feature appear to .xsn file), list and Prog ID.

The RegistrationID element is used to specifiy the ID of RegistrationType. If RegistrationType is “ContentType”, to get Registration ID, open the document library settings, in the ContentType section click on the content type you
choose, then grab the hex string in the url after “ctype=” parameter.

If you use FileType as RegistrationType, then just add the “.doc” or “.xls” etc in the RegistrationID

If the RegistrationType is list or ProgID, John Holiday has a blog summarized all the RegistrationID, look it up!

Adding a CustomAction menu item is not that difficult, however, it is a bit tricky to hide/remove it. I will talk abou it in my next post – Customization ofSharePoint List Menu Item – Part 2 Hide Custom Action Item

Posted in development | Tagged: , | 1 Comment »

How do I trouble shooting- Parser Error Message: Unrecognized attribute ‘type’

Posted by chrissyz on May 5, 2009

Well, this is annoying… after some developers on my team played around ASP.NET framework (this is what I am guessing.. no one come to me to confess so far though :)) our SharePoint portal suddenly stop working and get this message



Server Error in ‘/’ Application.

Configuration Error


Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.


Line 14:       <section name="BlobCache" type="System.Configuration.SingleTagSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
Line 15:     </sectionGroup>
Line 16:     <sectionGroup name="System.Workflow.ComponentModel.WorkflowCompiler" type="System.Workflow.ComponentModel.Compiler.WorkflowCompilerConfigurationSectionGroup, System.Workflow.ComponentModel, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
Line 17:       <section name="authorizedTypes" type="System.Workflow.ComponentModel.Compiler.AuthorizedTypesSectionHandler, System.Workflow.ComponentModel, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
Line 18:     </sectionGroup>



Unrecognized attribute ‘type’.
Source Error:



Source File: C:\Inetpub\wwwroot\wss\VirtualDirectories\80\web.config    Line: 16

Version Information: Microsoft .NET Framework Version:1.1.4322.2407; ASP.NET Version:1.1.4322.2407

It took me some efforts to resolve this issue…

First of all, after some investigation, I found in IIS manager, our sharepoint site is pointing to ASP.NET framework 1.1. The fix will be adjust it back to ASP.NET framework 2.0 (Just right click the web site -> Properties->ASP.NET tab ->Choose the correct framework)

Now I re-render it again. This time I got page cannot be found error…Argh….so I tried re-registering ASP using Aspnet_regiis.

And then render the page again…now I got this error:

CS0016: Could not write to output file ‘c:\WINNT\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\root\a0f950ac\3f897461\fr-fr\App_GlobalResources.k8ft-2zy.resources.dll’ — ‘The directory name is invalid. ‘

OK, babe…whatever..This clearly indicate that the folder Temporary ASP.NET Files does not exist. So I went to My computer ->Properties->Advanced->Envrionment Variables. Make sure the folder System variables TEMP and TMP is pointing to exists on your computer and Network Services and aspnet accounts have full control of it.

Then after an iisrest and long wait, my dream portal finally appears on the screen!



Posted in development | Tagged: | 7 Comments »