SharePoint Feature Receiver Error ‘The EXECUTE permission was denied…’

15 03 2010

I got this error this morning when trying to activate a web feature in a site collection. It turns out that this is because the application pool running the web application (in my case ‘Network Service’) does not have the required permissions to run some SharePoint SQL stored procedures within the configuration database.

In order to fix this error you will need to give the application pool database role WSS_Content_Application_Pools ‘Execute’ rights on the following stored procedures:

  1. proc_PutObject
  2. proc_putClass
  3. proc_dropObject
  4. proc_getNewObjects

Once you have granted this role the correct permissions you will be able to activate the feature/perform the operation you were attempting before.

Hope this helps!

Advertisements




Getting field values of an SPListItem returned from an SPQuery – watch out!

16 02 2010

I have seen and read about this gotcha before but even so I still fell for it today and it took for a couple of hours to figure out so I’ve decided to blog about it.

If you are working with SharePoint items in code which you have returned using a CAML query then you should always populate the SPQuery instance’s ViewFields property. You must include in here all the fields for which you might need to get the value of later. Failure to do this will mean the returned SPListItem instances might not contain the data for certain fields and will throw an exception (usually ‘Value was not within the expected range’).

The ViewFields property is set like this:


    <fieldref name="Title" /><fieldref name="Created" /><fieldref name="ID" />

    

You can then access a fields value on an SPListItem instance using the normal code:


    SPListItem item = list.GetItemById(1);

    string Title = item["Title"].ToString();

    

Hope this helps!!





Removing a Custom Nintex Action

11 02 2010

Today I needed to remove a Nintex custom action that I had produced from my SharePoint environment and couldn’t see any options to do this on the ‘Manage Allowed Actions’ page in Central Admin . A quick Google (errm I mean Bing!) search revealed a forum thread at the Nintex connect website, the forum thread mentioned going into the database to remove the action.

I didn’t fancy doing anything that drastic! so I did some more searching and then I found out that there is actually a command line tool called ‘Naming.exe’ which is supplied with Nintex Workflow 2007 and resides in the following folder:

C:\Program Files (x86)\Nintex\Nintex Workflow 2007\

This tool is similar to STSADM and allows you to remove a custom action. To remove an action use the following command:

NWAdmin.exe –o RemoveAction

You need to give this command the namespace and type name of your adapter. After this command has run you will need to execute another command:

NWAdmin.exe –o RemoveSafeActions

This command will remove the references to the action assembly from the web.config files of your SharePoint sites.

Hope this helps!





Debugging SharePoint code when using PowerShell

10 02 2010

Note to self and anyone else who is interested –

When trying to debug code – a FeatureReceiver in my case with Visual Studio when you are using PowerShell to actually kick off the event you need to ‘powershell.exe’ process in addition to the normal w3wp worker processes. If you don’t do this then your breakpoints won’t get hit it seems.

Hope this helps someone!





SharePoint, AJAX UpdatePanel and SPWebPartManager woes

26 01 2010

If you are having trouble getting your AJAX UpdatePanel to update properly in a SharePoint page or Web Part then you have come to the right place. You may already be aware that to get an UpdatePanel working in SharePoint you need to add a an additional function to your code that alters the _spFormOnSubmitWrapper and the _spSuppressFormOnSubmitWrapper. See here for an example –

http://petesullivan.wordpress.com/2008/06/13/ajax-update-panels-and-sharepoint/

However!! If you are using a custom Master Page then watch out because there is another gotcha!

It seems that if the SPWebPartManager tag appears before the Form tag in your master page then your updatepanel will not update properly and most likely won’t display any content. This should be changed so the SPWebPartManager tag appears underneath the form tag, see below for an example –

Incorrect

<WebPartPages:SPWebPartManager ID="SPWebPartManager1" runat="server"/>   
<form id="Form1" runat="server" onsubmit="return _spFormOnSubmitWrapper();">

Correct

<form id="Form1" runat="server" onsubmit="return _spFormOnSubmitWrapper();">
<WebPartPages:SPWebPartManager ID="SPWebPartManager1" runat="server"/>

Hope this helps! 🙂





Creating Custom SharePoint Web Part Connections

25 01 2010

I created my first web part connection the other day and was surprised at how easy and effective it was. I thought I would walk through the process that is required to connect two custom web parts together.

In this brief tutorial I am not going to cover how to create a web part or how to deploy one. I will assume that you (the reader) already knows how to do this. All code in this tutorial will be written in C#.

1. To begin create yourself two web parts – one of these will be the ‘Provider’ and the other the ‘Consumer’. You can create these however you like either using the VseWSS extensions or perhaps in an empty class library project.

2. Create an interface similar to the one below –

 public interface IExampleProvider
 {
        String TestParam { get; }
  
 }

Inside this interface you should define any parameters that you wish to send to your ‘Consumer’ web part.

3. In your Provider web part ensure that it implements the interface you have just created –

 public class ProviderWebPart: WebPart, IGovernanceProvider
 {
 }

4. Next create a property that returns the interface and decorate it with the  ConnectionProvider attribute. The parameters of  are the display name and the real name (ID) of the connection.

 [ConnectionProvider(&quot;Test Parameter&quot;,&quot;ExampleID&quot;, AllowsMultipleConnections=true)]
 public IExampleProvider GetExampleProvider()
 {
    return this;
 }

5. Finally for the Provider web part you need to ensure that the parameter property from your interface is implemented –

protected string _TestParam = &quot;&quot;; 
public string TestParam 
{
 get { return _TestParam; } 
}

6. Now its time to setup the Consumer web part, in your consumer web part class define a method that will accept the interface as a parameter and decorate it with the ConnectionConsumer attribute.

private IExampleProvider exampleProvider;
[ConnectionConsumer(&quot;Site URL&quot;)]
public void RegisterProvider(IExampleProvider provider)
{
   this.exampleProvider = provider;
}

7. You can now retrieve the value/values that have been sent to the consumer web part by calling the properties of the exampleProvider. Note you should check if a connection has been made first by seeing if the exampleProvider is null.

string myParam = this.exampleProvider.TestParam;

8. Deploy your two web parts by whatever method you wish, when you add the web parts to the page and click the ‘edit’ dropdown you should see a new menu option called ‘Connections’. The menu will appear on both the provider and consumer web parts but you only need to configure one.

Consumer Web Part:

image

Provider Web Part:

image

9. You are finished!

I hope you enjoyed this brief tutorial into web part connections, if you have any questions then feel free to leave a comment!

Hope this helps 🙂





Enabling .NET 3.5 support in your SharePoint environment – ‘The easy way’

19 01 2010

I used enable this support manually i.e. opening up the web.config file and making the necessary changes. I felt that this was a safer way to ensure that nothing went wrong. Recently though I have found a much better way to do this – Jan Tielens has a blog post on how to enable .NET 3.5 in SharePoint by using Visual Studio to modify the web.config for you, it works very well and is really quick to do.

You can find his blog post here –

http://weblogs.asp.net/jan/archive/2008/10/10/enabling-net-3-5-in-sharepoint-2007-sites-the-lazy-way.aspx

Thanks Jan!  (@jantielens on Twitter)