Saving Site as a Template Results in an Error in SharePoint 2010

 When you try to save a template in SharePoint 2010, you may receive an error at Microsoft.SharePoint.SPSolutionExporter.ExportWebToGallery where the system fails to upload the created solution in solution gallery.

 If you receive the Runtime error, first disable custom errors in application web.config. More info here..

To find the cause of problem, try running the command from Powershell by which you can trace ULS log.
$Web=Get-SPWeb http://site

The most common error is the duplicate feature folder in farm's 14 hive. If you have saved a site with same name anywhere in the site, try retracting the solution first. As soon as the feature folder is available again, the template will be saved/copied successfully.

How to override Core Results Web Part's limit of 50 results per page?

By default "Core Results Web Part" can result a maximum of 50 results. But grouping results require as many items as per requirement. To achieve this, we need to create our own CoreResults Web Part. The following code snippet help to achieve that.

public class cvsearch : CoreResultsWebPart
        protected override XPathNavigator GetXPathNavigator(string viewPath)
            QueryManager queryManager = SharedQueryManager.GetInstance(Page).QueryManager;
            queryManager[0].ItemsPerPage = 100;
            XmlDocument xmlDocument = queryManager.GetResults(queryManager[0]);
            return xmlDocument.CreateNavigator();

How to get the folder of SPListItem?

Need to get the item's parent folder in an event/feature receiver? The code snippet below seems to be the most practical way to do that.

foreach(SPListItem item in Items)
    SPFile fItem= item.Web.GetFile(item.Url);
    SPFolder folder = fItem.ParentFolder;

How to get recurrence events? For Today and for this Month?

SharePoint provides powerful calendar object model support for developers to leverage on. As it suffers from the lack of kickass documentation, one gets used to it with practice.

Recurring events are such. The major task with such events is to query them correctly so as to avoid in code checks which can burden the web part's performance.So use SpQuery properties correctly.

For example, to get all the recurrence events for this month:

//Get the first day of the Month
                DateTime caldate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                SPQuery query = new SPQuery();
                //Check the  tag, that's important to retrive a month of events including the recurrence one
                query.Query = "";
                query.ExpandRecurrence = true;
                //feed the month's first day to query
                query.CalendarDate = caldate;
                //fire the query to get list of items
                SPListItemCollection items = lst.GetItems(qry);

As a second example, to get all the recurrence events for today
//Get the date for today
                DateTime caldate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
                SPQuery query = new SPQuery();
                //Check the  tag, that's important to retrive all events including the recurrence one for today
                query.Query = "";
                query.ExpandRecurrence = true;
                //feed the month's first day to query
                query.CalendarDate = caldate;
                //fire the query to get list of items
                SPListItemCollection items = lst.GetItems(qry);

So if the dates are correct and CAML are well formed, we get our results correctly.

SharePoint on Cloud

SharePoint 365 is here! Now that's an edge.

From the SharePoint Blog
Whether you’re a small business or large enterprise the best way to learn about a new product offering like Office 365 is to experience it for yourself. From there it’s easy to build a plan that fits your business needs and make it your own.
·        Try it out - If you didn’t sign up for the beta back in April I would check out the Office 365 site and try it out today.
·        Develop a migration strategy and plan - There’s an immediate cost benefit to be gained by moving all your My Sites, Team Sites and Intranet Sites to SharePoint Online and the SharePoint Online planning guide for Office 365 will help you get started.
·        Customize and Extend with business solutions - Simplifying routine tasks using online forms and workflows is a great place to begin and for developers theSharePoint Online Developers Guide will help you quickly build simple applications and extensions tailored to your business.

How long a particular piece of code took to execute?

The Stopwatch class under the System.Diagnostics namespace is the key. The Stopwatch class makes it easy to use the high resolution timer in your code.

        // Create new stopwatch
 Stopwatch stopwatch = new Stopwatch();
 // Begin timing
 // Do something
        // Code Here
 // Stop timing
 // Write result
 Console.WriteLine("Time elapsed: {0}",stopwatch.Elapsed);

The Taxonomy feature (Feature ID “73EF14B1-13A9-416b-A9B5-ECECA2B0604C”) has not been activated

Use the following command to activate the farm level "Taxanomy Feature" on your SharePoint 2010 farm before you try to add a custom column of the Managed Metadata type.

STSADM -o activatefeature -id 73EF14B1-13A9-416b-A9B5-ECECA2B0604C -url http://<ServerName>
<ServerName> is the name of the server hosting SharePoint.

SharePoint, Query & Large Result Set

SharePoint Server 2010 provides a class titled "ContentIterator", We can use it to query on lists with large number of rows.
We should consider using this class if our query returns more than 5000 items. The ContentIterator divides the list into batches and runs the query against one batch of list data at a time. For example

protected void OnContentIterator(object sender, EventArgs args)
     SPQuery listQuery = new SPQuery();
     listQuery.Query = "< Query >";
    SPList list = SPContext.Current.Web.Lists["List"];
    ContentIterator iterator = new ContentIterator();
public bool ProcessError(SPListItem item, Exception e)
   // Process the error
   return true;
public void ProcessItem(SPListItem item)
   // Process the item

Visio Stencils for SharePoint 2010

On John Chapman's blog, he has compiled the graphics of SharePoint 2010 for using in Visio!


Please note: The stencils may not have all SharePoint icons and graphics, but they have the majority of them. Also, some stencil graphics have been named while others have not been.

Royal Mail turns to Microsoft SharePoint 2010 for Help

Microsoft SharePoint 2010 has been installed by the Royal Mail to help it reduce outgoings and improve its IT infrastructure.

The move is part of a "rapid modernisation" of postal services to help fend off increased competition and the threat of privatisation.

SPDisposeCheck : SharePoint Dispose Checker Tool

SPDisposeCheck is a tool that helps developers and administrators check custom SharePoint solutions that use the SharePoint Object Model helping measure against known Microsoft dispose best practices. This tool may not show all memory leaks in your code and may produce false positives which need further review by subject matter experts.

SPDisposeCheck tool can be downloaded here