# Visual Studio 2010 Installation Issue – Setup Failed with HRESULT -2147467259

If you Visual Studio 2010 setup keeps failing when it tries to install the Visual C++ runtime, here’s a quick fix for you.

Try installing one of the Visual Studio 2010 Express Editions (I did the Web Edition: http://www.microsoft.com/web/downloads/platform.aspx) and then run the VS2010 installation.

I think it has something to do with mounting the ISO as a drive.

# Icons & Illustrations for SharePoint Architecture Diagrams

A picture is worth a thousand words.

Like me if you spend a lot of time writing up functional specs and architecture diagrams and are looking for ways to convey your ideas through illustrations, here are a few pointers.

Search the Hive

The 12 (now 14) hive has a wealth of icons. The images in the png formats are the slightly larger, higher resolution ones. You can find them at 14\TEMPLATE\IMAGES. Here are a few samples.

Visio 2010 SharePoint Workflows

These are new ones, the icons in this stencil are vector based and can be resized without blurring.

Set the filter type to icon and clipart and you do come across some good gems. Remember to check the copyright on the images before using them.

SmartArt in PowerPoint 2007 & 2010

The SmartArts are a powerful tool to illustrate your ideas and need to be used wisely.

Play around with the various styles to get the look you want. Here’s one I built for a functional spec recently.

Here’s a diagram I built today to document a web part. The icons came from Google, the Hive and good old Visio.

Snipping Tool

My favourite tool to get screen grabs, and save them to files if necessary, is the Snipping tool. This has been built into Windows since XP SP2 and is a really handy utility. To get to it just type snip in the Start menu and you should see the Snipping Tool.

One of the first things I do on a new installation is to disable the Red outline from the Option menu. FYI: All of the images above were snipped and saved to disk using the Snipping Tool before being inserted into Live Writer.

# .NET 4 Free Beta Exam Vouchers

Looks like I somehow missed this. Free vouchers for the .NET 4 (Visual Studio 2010 Beta Exams) are available online in the Born to Learn blog.

I couldn’t register for the 71-515 (TS: Web Application Development with .NET 4) exam as it was booked up but there were seats still available for the other two exams that I registered for today.

You need to take the exams before 30-Apr, so you have almost a month to get prepared. You can also make use for the pilot beta preparation resources that other candidates are sharing, see the ‘Preparing for the Visual Studion 2010 beta exams’ post by Krista.

# SharePoint Client on Windows 7 Phone

Yesterday I was excited when I could download the Win 7 dev kit, but that turned to disappointment when I realised that I could only run the application that I deployed and not try out the other stuff on the phone.

Today, thanks to Dan Ardelean I was able to unlock the Windows 7 Phone emulator. So here I was poking around only to be pleasantly surprised to see the SharePoint client built in to the phone.

Here are the first screenshots you’ll see of the Win7Phone SharePoint client.

# Get Safe File Name

Here’s a quick utility that might come in handy. More than once I’ve seen code where the invalid chars were hard coded. The Path.GetInvalidFilenameChars has been in the .NET Framework since 2.0.

The thing is you would expect something like this to be in the framework itself.

        /// <summary>
/// Removes invalid characters from the string that is passed in.
/// </summary>
/// <param name="name">The name of the file.</param>
/// <returns>The safe name with invalid chars removed.</returns>
public static string GetSafeFileName(string name)
{
var safeName = new StringBuilder();
foreach (var c in name)
{
if ((from p in Path.GetInvalidFileNameChars() where p == c select p).Count() == 0)
{
safeName.Append(c);
}
}
return safeName.ToString();
}

Chris Martin posted an even tighter version of this code in the comments below. Thanks Chris.

var invalid = Path.GetInvalidFileNameChars();

return new string((from p in name
where !invalid.Contains(p) select p).ToArray());

# SharpSvn: A Primer

The SharpSvn library basically gives you a .NET interface to all the operations that you would normally perform through a tool like TortoiseSVN.

I found myself needing this exact library while writing a tool that changes files that have been checked out from SVN.

The problem with manipulating files that are under SVN is that you need to be careful about renaming files (and sometimes even deleting). If you don’t do it through the SVN api then you will end up with duplicates files/folders in SVN since SVN thinks that it’s a new file.

To solve this I finally got a chance to crack open the SharpSVN library which is used by my favourite AnkhSVN.

1. Download the latest library from http://sharpsvn.open.collab.net/. You have to pick between either 1.5 or 1.6. I went with 1.6 and didn’t run into any issues. I think this is based on the version of the SVN server that your connecting to.

2. In your Visual Studio project add a reference to the following assemblies.
- SharpSvn.dll
- SharpSvn.UI.dll (Only needed if you need the UI to prompt for login)

3. If like me your building on a 64 bit OS and you want your app to run on a 32 bit OS, make sure the project that references the SharpSvn.dll is set to Build for the x86 Platform. (Build –> Configuration Manager – Solution Platform)

4. Write your code using the SvnClient object. Here are some samples from the SharpSvn Wiki and some that I wrote.

CheckOut

public void CheckOut()
{
using (SvnClient client = new SvnClient())
{
client.CheckOut(
new Uri("http://svn.collab.net/repos/svn/trunk/contrib"),
@"c:\wc");
}
}

Add new files to the working copy

using(SvnClient client = new SvnClient())
{
// TODO: Set optional settings on args

}

Check if a given path is a valid SVN working copy

public static bool IsWorkingCopy(string path)
{
using (var client = GetSvnClient())
{
var uri = client.GetUriFromWorkingCopy(path);

return uri != null;
}
}

Find out if a particular folder/file has been marked for deletion.

public static bool IsDeleted(string path)
{
if(!IsWorkingCopy(path)) return false;

bool isDeleted;
using (var client = GetSvnClient())
{
Collection<SvnStatusEventArgs> args;
client.GetStatus(path, out args);
isDeleted = args.Count > 0 && args[0].LocalContentStatus == SvnStatus.Deleted;
}
return isDeleted;
}

What’s even more awesome about the guys who wrote this library actively support it (even over twitter, thanks http://twitter.com/srijken!).

And that was even before I found out that they have a ready made .wxs file for integrating the .dlls into my WiX installer package. Awesome!

# Workflow does not start automatically when bulk inserting items

This had me tripped for a while. I was bulk inserting items (~800) to a list which had event receivers as well as a workflow attached.

The problem was that the workflow was not being triggered. Or if it did it just hung at In Progress.

After poking around for more than an hour I discovered that if I inserted a single item it worked. So to fix the issue I added a ten second sleep (Thread.Sleep) between the inserts and the workflows are triggering away happily.

# Implementing Business Rules in a SharePoint list

On the project I am currently working on I had to implement a custom business rule for a list. The requirement was that only users in an Administrator group should be allowed to edit a particular field. All other users can edit that list but they are not allowed to touch that particular field.

Given that this was the first time I had to do this in SharePoint I did some research to figure out the best practice but came up empty. Most of suggestions were to customize the edit form and add the logic there. This clearly will not work since the business rule validation is in the UI and not in the actual list. Hence leaving it open for anyone to open in datasheet view or any of the other numerous ways (e.g. web services) to break the business rule.

[Note: While researching for this post I did come across the ‘Enforcing Custom List Item Data Validation’ best practice by SharePoint patterns and practices group, which essentially makes the same recommendation as this blog post.]

SharePoint 2010 makes it a little easy with the Validation Formula feature which lets you add business rules to any list directly from the UI. But with SharePoint 2007 you’ll need to use an SPItemEventReceiver to implement your business rule.

There is a good code sample on validating a list in the List Item Event Receivers article on TechNet.

# Visual Studio Maintenance Mode

I started working my way through the hands on labs in the SharePoint 2010 Developer Evaluation Guide and found that I was missing the Visual Studio 2010 Command Prompt in my installation.

Gabriel’s post explained why. I typically don’t install VC++ on my dev boxes and apparently this is a known bug in VS 2010 where the command prompt doesn’t get installed if VC++ is not installed.

What really prompted me to post this is this nice feature new to 2010. I realized that I didn’t have the installation iso but gave it a try by going to Add/Remove programs and going through the Add/Remove features in VS 2010. The dreaded dialog to pick the installation path came up.

I was almost about to give up when I noticed the Download button. And viola the setup actually connects directly to the download servers at Microsoft and get’s only the items that have changed. It also went ahead and noticed updated Silverlight Tools and got them as well.

In the words of @AriBakker. Sweet. Sweet indeed.

# Review: Gmail Extension

Chrome opened public extensions just a few days ago and already the quality of extensions available are awesome.

Take a look at the Google Mail Checker Plus extension. The preview window itself is awesome and it works for GAFYD as well.