Today I found a nice Visual Studio Extension for working with localization and resx files: Resx Resource Manager. This extension provides an additional view in your project and scans all the resx files. I would recommend it to all projects where you have to translate your interface. Here is how it looks in my project:
It can also assist with some machine translation from Bing and MyMemory:
Another good thing is the Export and Import to and from Excel. Wonderful if you need help from Non-developers.
You can do many things with it. Here are two examples for simple but very useful functions:
1. Show which browsers support a css attribute:
There is much more, like less and coffeescript parsing. Just check the documentation. And it is fully appliable in SharePoint development.
Less and Coffeescript
Now using less and coffeescript (update: and typescript) can be really easy even in SharePoint. Whenever you save a .less file or .coffeescript, it will create a corresponding file with .css or .js file extensions in the same folder. So you can write your styles in less and scripts in coffeescript and reference the auto-generated css and js files.
UPDATE: For some reason the css is not generated when I run Visual Studio 2012 on Server 2008 with Web Essentials, but it works fine on my Windows 8 machine. To play around with less, you can use this demo site (creds to @irishbuzz on so).
Next: Typescript and SharePoint
Recently I talked about a WithWeb-pattern as described in Jonas Nilssons blog where you can isolate the disposal logic in one place. Another thing is to isolate unsafe updates:
public static class SPWebExtension
public static void UnsafeUpdate(this SPWeb web, Action<SPWeb> action)
Log.Info("Trying to do an unsafe update on a web: " + web.Title);
web.AllowUnsafeUpdates = true;
catch (Exception e)
web.AllowUnsafeUpdates = false;
The Log class is my own class which I presented in my previous post.
Use LINQ to check if user is in a group. Create an extension method.
public static bool InGroup(this SPUser user, SPGroup group)
.Any(g => g.ID == group.ID);
EDIT 2011-01-22: There is a shortcoming of this method. You won’t get a user which is in group through a AD group. You’ll get only users and ad groups. But there is another method to check if a user is inside an AD group.
How could we combine them?…
I think we must start from group this time, not from user:
public static bool HasUser(this SPGroup user, SPUser user)
var users = group.Users.Cast();
var samAccount = Regex.Replace(user.LoginName, @".*\\(.*)", "$1", RegexOptions.None);
var exists = users.Any(u => u.LoginName.Equals(user.LoginName));
var ctx = new PrincipalContext(ContextType.Domain);
foreach (var u in users)
var login = u.LoginName;
var groupName = Regex.Replace(login, @".*\\(.*)", "$1", RegexOptions.None);
var grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, groupName);
if (grp == null) continue;
var principals = grp.GetMembers(true);
exists = principals.Any(p => p.SamAccountName.Equals(samAccount,
if (exists) break;
Using Regex to get the samAccount from loginname is taken from the awesome answer on StackOverflow.
After debugging I have found the Content Type Ids for Image, Audio and Video in the assets library. These content type ids are not present in SPBuiltInContentTypeId.
public class SPBuiltInContentTypeIdExtension
public static SPContentTypeId Video =
public static SPContentTypeId Audio =
public static SPContentTypeId Image =
These three asset content types inherit from Document CT (“0x0101”) and have “0x0101009148F5A04DDD49CBA7127AADA5FB792B” in common, which is the content type id for multimedia content type. So if you want to check if it is a multimedia, use this id.
You can see the content type id when you go to Site Actions – Site Settings – Content Types. Click on a content type you interested in. In the address bar of your browser find ?ctype=.
Eller i koden så kan du göra så här:
var id = properties.Web.AvailableContentTypes