SharpSvn: A Primer
Posted by merill | Filed under .NET
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())
{
SvnAddArgs args = new SvnAddArgs();
// TODO: Set optional settings on args
client.Add(@"C:\file\in\workingcopy", 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!
Tags: sharpsvn, subversion, tortoisesvn
Workflow does not start automatically when bulk inserting items
Posted by merill | Filed under SharePoint
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.
Tags: bulk insert, workflow
Implementing Business Rules in a SharePoint list
Posted by merill | Filed under SharePoint
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.
Tags: sharepoint; business rule; form validation; sharepoint 2010
Visual Studio Maintenance Mode
Posted by merill | Filed under Tips
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.
Tags: command prompt, setup, visual studio 2010
Review: Gmail Extension
Posted by merill | Filed under Uncategorized
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.
Installing Office Web Apps on Windows 7
Posted by merill | Filed under SharePoint 2010
If you haven’t heard of Office Web Apps before it’s basically Word, Excel, PowerPoint and OneNote running inside a browser. It lets you edit documents right within the browser.
A bit of history
You can be forgiven to think that this is all new. The truth is that a skunkworks team within Microsoft built a version of this (code-name NetDocs) way back in 2000 (even before .NET was launched). It is believed that Steven Sinofsky (now head of Windows 7, previously head of Microsoft Office) managed to get this project killed off. Many years down the line Google snagged a lot of the guys from that original team (including the guy who Ballmer threw a chair at).
Back to the Article
Right. Back to our installation. The key document that you need to follow is this Deploy Office Web Apps guide on TechNet.
Pre-Requisites
- The SharePoint 2010 beta needs to be installed
- The documents must be created with the new Office 2010 beta application in order to be editable (you can view all documents but to edit them in the browser you need to at least open and save the .docx using the latest beta of Word/Excel)
Installation
1. Download Office Web Apps from the download centre (here is the direct link). If you couldn’t figure it out the English version is the one named WcServer_en-us.exe
2. Extract the installation and edit the config.xml in order to allow installing on Windows 7. To do this run the following command from the command prompt.
WcServer_en-us.exe /exctact:C:\WCServer
If you have installed SharePoint 2010 on your Windows 7 you will be familiar with what this does.
Now you need to edit the config.xml in extract location and add the following line to \Files\Setup\config.xml just like you did for the SharePoint 2010 install.
<Setting Id="AllowWindowsClientInstall" Value="True"/>
That is it. Run setup.exe and follow the rest of the guide in the Deploy Office Web Apps article and you will be able to edit Office documents from within the browser in no time.
NB: I did not have to run any of the PowerShell scripts as the features were all activated. I simply created a new Web Application and uploaded some documents and was able to edit in the browser.
Tags: 2010, install, office web apps, SharePoint
Installing SharePoint Server 2010 on Windows 7
Posted by merill | Filed under SharePoint 2010
Here’s a quick summary of how I installed the public beta of SharePoint Server 2010.
Minimum Requirements:
- Windows 7 64 bit: What this means is that your workstation needs to be 64 bit and you need to have the 64 bit version of Windows 7 installed.
Setup:
The key document that you need to follow for installing on Windows 7 is this article: Setting Up the Development Environment for SharePoint Server
Key Notes:
- This was installed on Windows 7 Build 7100
- I had UAC turned off
- I already had Visual Studio 2010 Beta before installing SharePoint
- You need to manually download and install the pre-requisites for SharePoint 2010
- You need to extract the setup (using /extract), change an xml file before being able to run setup on Windows 7.
Minor Deviation:
The only part of the guide that I was forced to skip was #5 of ‘Step 3: Install SharePoint’
The reason was that the install for the SQL Server patch kept asking for the other files in the multi-part zip. (Remember to unzip the file even though it has a .exe extension)
Summary:
Excluding the download times it took about 30 minutes to install SharePoint server on my Dell XPS laptop which has 4GB of RAM.
Although there is no guide published yet I was able to install Office Web Apps on my laptop as well, that guide will follow next.
Tags: 2010, install, SharePoint, windows 7
Windows 7: WiFi slow to connect or Limited Connectivity
Posted by merill | Filed under Tips
I’ve been having this frustrating issue for the last month where the laptop would take about 10 minutes before it was able to connect to the internet. This happened even when the machine came back from sleep/suspend mode.
The Wifi connection would be detected immediate but I would not get an IP from the DHCP server. I always had to fiddle around by disconnecting and connecting a few times.
Well today I got down the source. The problem was to do with the Virtual Machine Network Services that were installed when I added Virtual PC. Once I went into the WiFi Adapter properties and removed the Virtual Machine Network Services I was able to get my PC back to instant connectivity.
Tags: windows 7; wifi; limited connectivity; slow to connect
CKS: World Clock and Weather WebPart with Proxy Support
Posted by merill | Filed under Utilities
I recently had to add proxy support to the Community Kit for SharePoint: World Clock and Weather WebPart.
IT Teams usually like to lock down the proxy server and are not happy when they need to allow anonymous access for outgoing requests.
Looking around none of the the free ones seem to support this. Not even the cool, free Silverlight one from Bamboo Solutions.
So I added proxy support to the CKS World Clock and Weather WebPart that was released on CodePlex (v1.0.15 to be exact). I looked at the licenses and I don’t think I’m breaking any of them by sharing the source code and the setup over at MSDN Code Gallery.
There were numerous posts on various forums wishing to enable proxy support. So here’s hoping someone might find it useful.
Download CKS: Weather WebPart with Poxy – Setup
Tags: SharePoint, weather
Google Wave Invites
Posted by merill | Filed under Tips
UPDATE: No more invites. Sorry guys I’ve given away all my invites on a first-come first-serve basis. Cheers!
I’ve given away most of my invites over Twitter but there are a few remaining though. So if you’d like a wave invite drop me a mail or leave a comment with your email address.
One tip I’ve found useful on my first day is to see public waves using with:public. The list is like a fire hose so I usually add some criteria e.g. ‘sharepoint with:public’ to see all public sharepoint waves.