Posts

ProcessBatchData Helper Class

There are a few ways to add multiple rows to a SharePoint list. The iterative approach (i.e.: line by line) is simple, but this pattern will fail a CAF report. The better way to get the data up is loading a batch file using the ProcessBatchData method on your trusty SPWeb object. (The official blurb on the method is  here .) The problem with this is that is requires a well formatted XML string. The easiest way to accomplish this is to writer a helper class and it is quite a life saver. Here is the class, followed by a sample of how to use the code.    public class ProcessBatchDataHelper     {         private const string ProcessBatchStartXml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";         private const string ProcessBatchRowsStartXml = "<ows:Batch OnError=\"Continue\">";         private const string ProcessBatchEndXml = @"</ows:Batch>";     ...

Token Replacement in Visual Studio

I was working on a simple WCF service, including a generic handler (.ashx). My code looked good until I tried to access the url - it started complaining that it did not know what ' $SharePoint.Project.AssemblyFullName$ ' was. A little digging ( here  and here  ) revealed at VS will not replace its tokens in all file types - you may need to specify them in the project file. Generic handlers are one of those types. So, first I unloaded the project and added the following to the property group: <PropertyGroup>  <TokenReplacementFileExtensions> ashx </TokenReplacementFileExtensions> </PropertyGroup> I then reloaded the project and redeployed. Too easy.

Create a new SharePoint Farm: Local accounts should only be used in stand alone mode

I was creating my new VM and installed a SharePoint Farm on the local machine. Easy enough. All was good until I tried to run the configuration wizard. That is when it all when wrong. I got the fantastic error message: Local accounts should only be used in stand alone mode Some simple searching brought my to this post ( here  ) that gave me the solution. Basically, you need to run the installation in PowerShell (using New-SPConfigutionDatabase ), as it exposes properties that are not available through the wizard. Once the database has been created, SharePoint thinks it has a Farm and the configuration wizard can continue on its merry way. Its pretty simple when you know how ....

SharePoint 2010 Code Samples

I have come across the following code samples for SP 2010 development on the Microsoft site. It is full of helpful code snippets and solutions that will probably save me a lot of searching. The samples are  here

Disable all event receivers in SharePoint 2010

I found the following page( here  ) about disabling global event receivers. A fantastic post that solves a very specific need. The crux of the solution is as follows: public class MyClass {   SPListItem i = SPContext.Current.Web.Lists["Blah"].Items[0]   HandleEventFiring handleEventFiring = new HandleEventFiring();   handleEventFiring.DisableHandleEventFiring();   try   {      i.Update();   }   finally  {     handleEventFiring.EnableHandleEventFiring();   } } public class HandleEventFiring : SPItemEventReceiver {        public void DisableHandleEventFiring()       {           this.EventFiringEnabled = false;        }        public void EnableHandleEventFiring()       {   ...

Cannot login to SharePoint 2010 site created as a Host Header Site Collection

I was creating a development environment for a fellow developer in a new VM. I had gone through my checklist for a new VM: 1. Create the Web Application 2. Create the Host Header Site Collection 3. Add the bindings in IIS 4. Update the hosts file to point 127.0.0.1 to the host header 5. Updated DisableLoopbackCheck ( see here  ) 6. Give all the users excessive permissions Still nothing. The site would not render, even though the Farm Solutions where OK and my deployment log has not errors. I found the solution in the post ( here  ) and on the Microsoft site (  here ). I needed to add a Multi-String registry key named  BackConnectionHostNames to the registry at HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0  and add the host headers.

SharePoint 2010 Client side script to check if a user is in a SharePoint group

The following script looks in the SharePoint object model if the current users exists in the SharePoint group 'My Group Name'. If the user exists, then the button 'My Button' is hidden: ExecuteOrDelayUntilScriptLoaded(disableControls, "sp.js"); function disableControls() {     clientContext = new SP.ClientContext.get_current();     currentUser = clientContext.get_web().get_currentUser();     clientContext.load(currentUser);     this.collGroup = clientContext.get_web().get_siteGroups();     clientContext.load(collGroup);     clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); } function onQuerySucceeded() {     var groupEnumerator = collGroup.getEnumerator();     while (groupEnumerator.moveNext()) {         var oGroup = groupEnumerator...