Tags: c-sharp

Programmatically compile Audiences in SharePoint 2010

According to the documentation for the SharePoint 2010 SDK, you cannot trigger Audience compilation programmatically. Well—that’s not true. It isn’t documented, but it is possible. The painful thing about it is that you must know the ApplicationId of the UserProfileService application. This is where reflection comes in extremely handy! Read More →

bulkRename v2.0 released

I’ve converted my bulk file renaming utility from VB.NET to C# and made use of a command line arguments parsing library so that it will accept folders and regex patterns with spaces in them. It behaves a bit weird if you don’t encapsulate your arguments in quotation marks (“) or if you forgo the use of an equals sign (=) between the parameter flag and its argument, but those are small concessions to make.

You can download v2.0 to use yourself. Read More →

Simple file access concurrency in C#

When working without the safety net of a RDBMS in a multi-user environment, file concurrency may become an issue. In a project I’ve been working on recently, XML files are being used as the custom data store. This is all fine and dandy for now—with a user base of 1 (myself)—but when the app is released “into the wild”, concurrency may become a serious problem.

To remedy this problem (in a simple, no-nonsense fashion), I have been relying on a mutex file to exclude concurrent writes to the XML data store; it has been holding up just fine in my simulated scenarios. The mutex allows for one web request to read in the XML, modify it, and write back to it without being usurped by concurrent requests. There is a fail-safe mechanism which will wait for up to 3 seconds (30 attempts to lock the file) before failing outright. Read More →

Custom error messages with ValidationSummary in ASP.NET

Sometimes, there are problems encountered in a code-behind file that don’t warrant the extra work and mark-up that would otherwise be required to add CustomValidator controls to the page for displaying error messages to the user through your ValidationSummary. Wouldn’t it be nice if you could (somewhat) easily take care of it in your code-behind file alone, without adding additional clutter to your UserControl/Page/etc.? Well, you can! The following IValidator extension class can be added to a Page‘s Validators list with ease for displaying custom error messages. Read More →