Thursday, April 29, 2010

SharePoint tips: Working in localized environment

My SharePoint tips or lessons learned in practice

In this post I would like to share my list of things to keep-in-mind when working on a SharePoint solution for a localized environment. All these are learned the hard way – after hours spent in debugging and troubleshooting. Hope this saves you some time :-)

Lesson 1: Strong internal name

When creating a new SharePoint field use strong internal name. This is well-known practice, but since this is my list of things to keep-in-mind, I will start with it. Here is why:

1. Using a strong internal name, you will have easy way to refer to the field in your code
2. You will have unique name (rather than “Title1”, “Title2” etc)
3. Once you take control and use your internal name code practice, you will have the choice not to work with names like: “Some_%20_Column_%20_Name” (and this might be pretty annoying sometimes), but “Some_Column_Name” or just “SomeColumnName”.

There are many different posts showing how to give specific internal name for your SharePoint field, so I will skip this part.

Lesson 2: Use "SPListTemplateType"

Don’t use this line of code when creating list programmatically:

Guid guid = web.Lists.Add(listName, String.Empty, web.ListTemplates["Document"]);

Simply because “Document” list template might be called “Документ” in a localized environment. Instead, better use this one:

Guid guid = web.Lists.Add(listName, String.Empty, SPListTemplateType.DocumentLibrary);

It even looks better!

Lesson 3: Use "SPBuiltInFieldId" enumerator

If you want to access built-in "Title" field in a localized environment, and you do something like this:

item["Title"] = "Some title";

You may end up with:

System.ArgumentException: Value does not fall within the expected range.
at Microsoft.SharePoint.SPFieldCollection.GetFieldByDisplayName(String strDisplayName, Boolean bThrowException)

This is why SharePoint team gives us "SPBuiltInFieldId" enumerator which can be used to access all built-in fields by GUID. So, the line above will look like this:

item[SPBuiltInFieldId.Title] = "Some title";

Lesson 4: Use “SPBuiltInContentTypeId” enumerator

When working with build-in content types, use "SPBuiltInContentTypeId" enumerator to get them. Don’t rely on display name, in a localized environment this will not work for sure!

Lesson 5: Use “SPRoleType”

Let’s say you have a list, and you need to set programmatically permissions for it. To do this, you have to get “Full Control” role definition. Which line of code is correct?

1. SPRoleDefinition role = web.RoleDefinitions["Full Control"];
2. SPRoleDefinition role = web.RoleDefinitions.GetByType(SPRoleType.Administrator);

And the answer is: both. But if the question is: “Which line of code is better to use?”, then the answer definitely is “2”.

Using "GetByType" method and "SPRoleType" enumerator to access a role definition will guarantee that you won’t deal with exceptions like: “Microsoft.SharePoint.SPException: Permission level cannot be found”.
Read more on this article...
Bookmark and Share

Thursday, April 22, 2010

Running SharePoint 2007 on .net framework version 4

As the latest .net framework is officially out you are definitely getting more determined to put your latest experiments out in the wild. No doubt it`d be beneficial to make use of those new features, optimizations and capabilities, but just not yet. SharePoint 2010 is close to official but even so - migration is to be faced in long term. We have to deal with existing setups on SharePoint 2007. So - does porting to .net 4 runtime worth it and how to achieve it.

  • Visual Stidio 2010 - the official release is free for evaluation, you can download it and give it a try
  • .NET 4 framework runtime - obviously ..
  • WSPBuilder ver 1.4 beta - a well known tool, pretty helpful if you want to leverage and speed-up working with SharePoint solutions
A small remark here goes to note that VS 2010 is targeted for SP 2010 solutions. You still have 2 projects for SP 2007 but they only consolidate building workflows. So inevitably we`ll have to rely on 3rd party tools. WSPBuilder is fairly useful and stable even in beta mode for the VS 2010 support. It`ll be used here after.

SharePoint solution example

Create new WSPBuilder project. Add new project item - visual web part. VS 2010 already have that template for SP 2010. It prepares for you a new webpart that loads a custom user control and a feature to deploy and setup all of that.

At this point you can succesfully package WSP, deploy and make use of your solution as usual. You`ve achieved usage of VS 2010. But we aim higher. So reach project properties and switch to .net version 4 compilation. At this point a web.config file will appear among the project files.

Once CLR 4 is targeted, you`ll get all the version 4 framework capabilities and extensions complied in .net 4 assemblies. Let`s take for our sample the Chart control, part of the 4 package. Place it on your user control and hook it up to a data source (alternatively you can download the source files provided).
And so we have our .net 4 solution ready. Lets face the configuration changes that will make it running.

At first of course we need to get the solution deployed. Fastest way goes through the "deploy" commant of WSPBuilder. But you can always deploy it the way you want. Just keep in mind that WSPBuilder (if you are using it) wont include in the output package any .net 4 assemblies, as it recognizes them as "unmanaged" code. So you`ll have to take care of assemblies deployment manually (eigher GAC or local bin folder of your web app)
"Copy to CAG" option works fine, just make a note that CLR 4 GAC is no longer at the same location, so verify for your deployed assmeblies in C:\Windows\Microsoft.NET\assembly\. The subfolder depends on the build type you are using - x86, x64 or MSIL for Any CPU.

When verifying for correct deployment, we`ll notice that the solution has been installed properly and even the feature may have been deployed, but not activated. That`s due to the fact that CLR 4 has totally different runtime engine than the present CLR 2. The legacy one cannot load assemblies compiled for version 4. Therefore on our current setup, SharePoint running on CLR 2 application pools cannot find the assembly pointed to contain the feature event receiver. Therefore feature fails to activate. If execution goes through the Central Admin application, even the feature deployment will fail. To overcome this, a SharePoint webapplication must be configured to run on the latest CLR version 4. For IIS 7 that goes through the application pool settings.

Once we switch an existing SharePoint web application to CLR 4, few additional settings are required in order to get it running.
Examining the web.config, there are few must have attributes that instruct the new runtime engine how to deal with a legacy application.

<compilation debug="true" targetFramework="4.0">
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<trust level="Full" originUrl="" /> - other security levels lead to issues, so this one is to be used temporarily

Browser support happens to be another issue stacked on the incompatibility list. Launching the site with the properly configured web.config will get you to a error screen, describing a weird configuration error. To prevent this for a tryout you can remove the compatibility descriptor file at ..\inetpub\wwwroot\wss\VirtualDirectories\xx\App_Browsers .. Of course it`ll leave you only on IE support.

Including the Chart control in out solution brings few more complexities marked in the web.config. Usually in practice those changes go through code, but for that sample you can manually merge the web.config file in your solution with the one of your web application. Few additional changes are also made in the provided solution files, in oder to allow sql data source to bind to a visual control through integrated security.

Once you have the configuration file properly extended, your site will load up same as before. CLR 4 would be in charge, and the freshly provided webpart that includes a chart control will load up smoothly.

At this point it`s up to you to decide whether to upgrade your existing solutions to .net framework version 4 and accordingly your SharePoint environments. Justification is quite subjective, as the most important change that must take place is the web application (pool) switch to CLR 4.

The solution sample is available for download (free registration required).
Read more on this article...
Bookmark and Share

Monday, April 12, 2010

iTechnology Announces Partnership With Nintex

Today, April 12, 2010 iTechnology has announced the formalization of strategic partnership with Nintex - a leading global innovator of Microsoft SharePoint products.

This partnership will establish further stability in the symbiosis between the two companies and will provide customers with quality solutions for a competitive price.

Nintex solutions and the iTechnology's capabilities in SharePoint consultancy and custom development along with the iTechnology Forms Accelerator - the electronic Forms Designer that goes beyond the InfoPath functionality - are the factors we all believe will provide stable solutions for the everyday challenges of each industry.

Here is what Wayne Woolston, Nintex managing director said about partnering with iTechnology:
“iTechnology’s strong SharePoint advisory and implementation capability plus their focus on SharePoint innovation perfectly place them to represent Nintex to their customers. Nintex is pleased to welcome iTechnology as a Nintex partner.”

Dima Ivahno, CEO of iTechnology says:
"The partnership between iTechnology and Nintex works to combine and extend the offerings of both companies. We believe that there are a number of companies who will achieve a great BPM comfort by implementing our advanced integrated solutions."

You can read more for this partnership in the official press release of iTechnology.
Please feel free to visit both companies on their websites and learn more about the solutions and services they provide.


Read more on this article...
Bookmark and Share