January 2010 - Posts
Sometimes you would like to accomplish some task on a Page which takes more time than is set as “timeout” and you are seeing Request timed out in your browser.
This type of error is not so informative for end-user and is not beautiful for a complete solution.
SharePoint default solutions solving this kind of problems with “Operation in Progress” page:
SharePoint API proposes SPLongOperation named class to solve this problem the same way in your custom solutions.
MSDN documentation:
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.splongoperation.aspx
This class provides you two main methods: Begin() and End(); and to properties: LeadingHTML and TrailingHTML, which can be set to show custom text.
Between calling Begin and End methods you can complete long operations. Code example:
// "this" is a Page
using (SPLongOperation longOperation = new SPLongOperation(this))
{
longOperation.LeadingHTML = "Your operation is in progress.";
longOperation.TrailingHTML = "Your operation is currently ..";
// start long operation
longOperation.Begin();
// do nothing 3 minutes
Thread.Sleep(60000 * 3);
// when operation will be finished
// user will be redirected to this page
longOperation.End("/_layouts/settings.aspx");
}
Windows SharePoint Services 3.0 (SharePoint 2007) using Windows Internal Database as database engine, which is 32-bit, even if it is installed as component of Windows Server 2008 64-bit.
New SharePoint – SharePoint Foundation 2010 using Microsoft SQL Server Express as Internal Database, which is 64-bit with 4 Gb limit per database.
To connect to this database you should just enter as a server name “your computer name”\SharePoint. Be sure that user account have required permissions. Computer Administrator account have this permissions. So you can use Windows Authentication option and enter Administrator as account.
If you will get error, then you can to check database server name from Central Administration:
Central Administration > Manage Content Database Settings > section: Database Information > Database server

In my case it is: “WIN-IFGBHK5GMNH\SharePoint”
If you are creating both ListTemplate and ListInstance in the same feature, then there is no problems and its Element Manifest could be something like:
<ListTemplate
Name="LDContacts"
DisplayName="Contacts"
Type="14001"
Description=""
BaseType="0"
OnQuickLaunch="FALSE"
SecurityBits="11"
Hidden="FALSE"
RootWebOnly="FALSE"
/>
<ListInstance
Id="14001"
Title="Contacts"
OnQuickLaunch="FALSE"
TemplateType="14001"
Url="Lists/Contacts"
RootWebOnly="FALSE"
/>
If you requirements is that you are defining ListTemplate in Site scoped feature and you need to define ListInstance in Web scoped feature. If you will try to divide this XML sections into to XML files and activate this feature you will see error message.
If you will explore SharePoint log files you can find following error description:
Feature Activation: Threw an exception, attempting to roll back. Feature 'FeatureName' (ID: '55266e29-72ba-4771-947f-5550d53e7b75'). Exception: Microsoft.SharePoint.SPException: Cannot complete this action. Please try again. ---> System.Runtime.InteropServices.COMException (0x81072101): Cannot complete this action. Please try again. at Microsoft.SharePoint.Library.SPRequestInternalClass.CreateList(String bstrWebUrl, String bstrTitle, String bstrDescription, String bstrListUrl, String bstrFeatureId, Int32 lTemplateID, String bstrDocTemplateType, ListQuickLaunchOptions qlOpt) at Microsoft.SharePoint.Library.SPRequest.CreateList(String bstrWebUrl, String bstrTitle, String bstrDescription, String bstrListUrl, String bstrFeatureId, Int32 lTemplateID, String bstrDocTemplateType, ListQuickLaunchOptions qlOpt) --- End of inner exception stack trace --- at Microsoft.SharePoint.Library.SPRequest.CreateList(String bstrWebUrl, String bstrTitle, String bstrDescription, String bstrListUrl, String bstrFeatureId, Int32 lTemplateID, String bstrDocTemplateType, ListQuickLaunchOptions qlOpt) at Microsoft.SharePoint.SPListCollection.CreateList(String strTitle, String strDescription, String strListUrl, String strFeatureId, Int32 templateID, String strDocTemplateType, QuickLaunchOptions qlOpt) at Microsoft.SharePoint.SPListCollection.Add(String strTitle, String strDescription, String strUrl, String strFeatureId, Int32 templateType, String docTemplateType, QuickLaunchOptions quickLaunchOptions) at Microsoft.SharePoint.SPListInstanceElement.EnsureListExists(SPWeb web) at Microsoft.SharePoint.SPListInstanceElement.ElementActivated(SPFeaturePropertyCollection props, SPSqlCommand sqlcmdAppendOnly, SPWebApplication webApp, SPSite site, SPWeb web, Boolean fForce) at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.
ProvisionListInstances(SPFeaturePropertyCollection props, SPSite site, SPWeb web, Boolean fForce) at Microsoft.SharePoint.Administration.SPElementDefinitionCollection.
ProvisionElements(SPFeaturePropertyCollection props, SPWebApplication webapp, SPSite site, SPWeb web, Boolean fForce) at Microsoft.SharePoint.SPFeature.ProvisionElements(SPFeaturePropertyCollection props, SPWebApplication webapp, SPSite site, SPWeb web, Boolean fForce) at Microsoft.SharePoint.SPFeature.Activate(SPSite siteParent, SPWeb webParent, SPFeaturePropertyCollection props, Boolean fForce)
To resolve this issue you should define in ListInstance element FeatureId where is defined ListTemplate. Now ListInstance block can be like:
<ListInstance
Id="14001"
Title="Contacts"
OnQuickLaunch="FALSE"
TemplateType="14001"
Url="Lists/Contacts"
RootWebOnly="FALSE"
FeatureId="5F119914-D14F-4147-A3C7-AF6E6AD2E2D4"
/>
Now feature should be activated successfully.
When you open SharePoint 2007 project in Visual Studio 2010 and click on Build/Rebuild command you will get following error message:
The type or namespace name 'SharePoint' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
It is because in SharePoint 2007 you have referenced assembly with version 12 and SharePoint 2010 has 14. Visual Studio just can’t find your referenced assembly in the GAC.
When you will open References for your project in Solution Explorer you will see that included assembly it not found:

Remove this “not found” assembly from References. Otherwise Visual Studio thinks that your new assembly is the same.
If you project was based on .NET 2.0 framework and you will click on Add Reference, then you can’t find new SharePoint 2010 assembly in menu. It is because SharePoint 2010 assembly is build on .NET 3.5 framework and you should to change Visual Studio project .NET framework version.
- Right click on you project in Solution Explorer and click on Properties.
- “Application” tab
- Change in “Target framework” combo box framework`s version to .NET 3.5 or newer
Now go to “Add Reference” and now you are able to select new SharePoint 2010 assembly.
After that you should be able to Build project successfully. (If you haven’t other problems)
Sometimes you don’t know which of all .NET framework types better fits you requirements, but you know that this class must implement some interface.
Following code gets all types that implements specific interface by interface name:
using System;
using System.Linq;
using System.Reflection;
class Program
{
static void Main(string[] args)
{
string interfaceName = "ICollection";
Type t = (new object()).GetType();
Assembly assembly = t.Assembly;
var types = from a in assembly.GetTypes()
where a.GetInterface(interfaceName) != null
select a;
foreach (Type type in types)
{
Console.WriteLine(type.ToString());
}
Console.ReadKey();
}
}
You can use other type from other assembly, for example, from SharePoint to search all types that has implemented necessary interface or load required assembly directly from DLL file.
I have already wrote in my previous post about searching sub controls by type.
Post: Searching for sub-control by type
Now I’m suggesting more useful extension-type method to extend all classes derived from Control class (for example Page, TextBox, DropDownList etc).
* Extension methods works in .NET 3.5 and newer.
public static T FindControl<T>(this Control control) where T
: Control
{
foreach (Control c in control.Controls)
{
if (c is T)
{
return (T)c;
}
if (c.HasControls())
{
T cTmp = c.FindControl<T>();
if (cTmp != null)
{
return cTmp;
}
}
}
return null;
}
Using examples:
TextBox firstLevelBox = Page.FindControl<TextBox>();
if (firstLevelBox != null)
{
// just for example
TextBox box = firstLevelBox.FindControl<TextBox>();
}
else
{
// control not found
}
Don't miss to add using directive:
using System.Linq;
Don't miss also to add using namespace where you have defined this extension method, when you want to use it.
First issue you can facing is you haven’t “Tools –> Create GUID” utility in your menu.
First what you should check is there required utility in “C:\Program Files\Microsoft Visual Studio 9.0\Common7\Tools\” directory named guidgen.exe
If you haven’t it you can download it separately from Microsoft site.
http://www.microsoft.com/downloads/details.aspx?familyid=94551f58-484f-4a8c-bb39-adb270833afc&displaylang=en
After downloading you should extract it.
After you have this utility on your computer you can add it to your Visual Studio menu. Follow this instructions to do that:
- Open Visual Studio 2008
- Tools –> External Tools
- Enter in a Title box “Create GUID”
- In Command box click on browse button named “…” and choose you extracted utility
- Finally click OK button and now you have GUID Generator in you Tools menu

More Posts