Brain Spew - Neville Mehta's Blog

Sunday, September 06, 2009

Tech Ed 09

So, it has been quite a while since I have blogged last, but I am planning on starting up again.
Im really looking forward to attending Tech Ed Australia 09 this week, being held on the Gold Coast. There are quite a few Readify guys presenting, so will be great to see them on stage doing what they do best!
I look forward to giving a few reviews of the presentations I watch this year. I am particularily keen to see a few of the .NET 4 ones!

Tuesday, June 19, 2007

Custom Actions in WSS 3 / MOSS 2007 - Part 1

Something that really frustrates my about WSS 3 and MOSS 2007 is the lack of documentation on alot of the object model as well as some of the CAML. One of the areas that really wasn't very helpful at all was the section on custom actions, so I thought I would write this post.

To begin with, just a quick introduction...custom actions in SharePoint simply refer to the buttons (such as in the "Site Actions" menu) and some of the menus across the site (such as in "Site Settings"). The best way to deploy these custom actions is definitley through a Feature. This post will show the simple way to display these custom actions. In the next post I will show how to use custom controls for the menu buttons.

Anyways, onto the code (or XML in this case)!

In the first example, I will create a custom action for the "Site Actions" menu.
To do this (and for the sake of the rest of the examples) we will begin with creating our feature manifest. Here it is:


<?xml version="1.0" encoding="utf-8"?>
<Feature Id="65245A4A-5D65-45ea-896F-6A6A808F3C80"
Title="MyCustomActionFeature"
Description="This feature adds custom actions"
Version="1.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="MyCustomActions.xml"/>
</ElementManifests>
</Feature>


Here is what the MyCustomActions.xml file looks like to add an extra item to the Site Actions menu (Note that in most of the examples below, I have just left the Url blank because these are just examples, but this would be where you put the Url of where you want to link to):


<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="PeopleAndGroupsAction"
GroupId="SiteActions"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="10"
Title="People and Groups"
ImageUrl="/_layouts/images/Actionscreate.gif">
<UrlAction
Url="/_layouts/people.aspx" />
</CustomAction>
</Elements>




Here is what the MyCustomActions.xml file looks like to add another custom actions menu item to the Actions menu of a list or document library.


<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Id="MyListActionsCustomAction"
GroupId="ActionsMenu"
Location="Microsoft.SharePoint.StandardMenu"
RegistrationType="List"
Sequence="10"
Title="My Actions Custom Action">
<UrlAction
Url="~site" />
</CustomAction>
</Elements>




Here is what the MyCustomActions.xml file looks like to add another section to the Site Settings page.


<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomActionGroup
Id="NewSiteSettingsGroup"
Location="Microsoft.SharePoint.SiteSettings"
Title="New Site Settings Group"
Sequence="10"
Description="" />
<CustomAction
Id="NewSiteSettingsGroupItem"
GroupId="NewSiteSettingsGroup"
Location="Microsoft.SharePoint.SiteSettings"
Sequence="10"
Title="My New Site Settings Item">
<UrlAction
Url="~site" />
</CustomAction>
</Elements>




Here is what the MyCustomActions.xml file looks like to add another section and custom action to the Central Administration page.


<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomActionGroup
Id="CustomCentralAdminSection"
Location="Microsoft.SharePoint.Administration.ApplicationManagement"
Title="Custom Central Admin Section"
Sequence="10" />
<CustomAction
Id="DoSomethingInCentralAdmin"
GroupId="CustomCentralAdminSection"
Location="Microsoft.SharePoint.Administration.ApplicationManagement"
Sequence="10"
Title="Do Something In Central Admin">
<UrlAction
Url="" />
</CustomAction>
</Elements>




As you can see, adding these actions is very easy. If you want to add a group like in the Site Settings and Central Admin examples, all you have to do is add the CustomActionGroup element and then use that ID for the GroupID in your CustomAction element.

There are also attributes such as RequiresSiteAdministrator and Rights which all some security trimming.

Also, if you are trying to find the appropriate value for the Location attribute, or GroupID attribute, there are a few listed in the SDK documentation. If you want more, you can simply look/search through the "Features" directory (%Program Files%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\) for the CustomActions written by Microsoft. After all, they used the same method Ive shown above for alot of the menus and buttons you see.

Anyway, I hope you have got the idea of custom actions. In one of the posts I have coming up I will show how to use custom controls (and hence use the ControlAssembly and ControlClass attributes) to render your custom actions.

Labels: , , , ,

Sunday, May 06, 2007

Setting up Reporting Services on MOSS 2007

Liam Cleary has an excellent series of articles(1, 2 and 3, ) on using the Reporting Services add on for MOSS 2007. I finally got the chance to play around with this today and was following Liam's instructions. They were excellent, but I did come accross a few things I thought I would mention quickly.
Firstly, you wont see the "SharePoint Integration" option in the Reporting Services Configuration tool until you install SQL Server SP 2.
Secondly, if you get an error saying "Exception of type 'Microsoft.ReportingServices.RsProxy.AccessDeniedException' was thrown." when trying to deploy your report project, make sure your ReportServer virtual directory in IIS does not allow anonymous access (not sure how mine got that way because I dont think its the default, and I definitley didnt enable anonymous access).

Labels: , ,

Friday, January 26, 2007

Cannot get Membership Provider with name [MembershipProvider name] error in SharePoint 2007 / WSS 3

Ive been doing some work with MOSS 2007 lately and came across this error:

Cannot get Membership Provider with name [MembershipProvider name]. The membership provider for this process was not properly configured. You must configure the membership provider in the .config file for every SharePoint process.

Just to save someone else the time of figuring out what the problem is, I thought I would let you know that the reason this is happening is because when you use a membership provider in SharePoint 2007 (or WSS 3) you must add the details about the membership provider in the web.config of the site you have created AS WELL AS in Central Admin so you can create site collection administrators etc.

Labels: , , ,

Tuesday, January 16, 2007

Uninstalling SQL Embedded Edition after a WSS 3 installation

If you ever try to install WS 3.0 on a single machine, an instance of SQL Server Embedded Edition is created, and this is will be your default for config and content databases. I wanted to use SQL Server 2005 Dev Edition. To do this, you must install WSS 3.0 with the farm option, not just a stand alone (single) option. But, the SQL Server Embedded databases dont uninstall. I looked around alot for info on uninstalling this, but eventually found this. Take a look at issue 33.

Sunday, December 31, 2006

Reporting Services "rsReportServerDatabaseUnavailable" error when installing TFS

I decided to install TFS today and after following the simple instructions on Cliff's notes for a team system install I came across a reporting services error halfway through the installation.
The error said something like "Cannot contact Reporting Services, make sure the database is installed and reachable blah, blah, blah" (obviously not a direct quote :-) ).

First thing I did was open the Reporting Services site in IE and found that there was an error saying that it couldnt access the location c:/inetpub/wwwroot/web.config "Access is Denied"...so I gave the NETWORK SERVICE account access to that location.
Then, I tried opening the site again and got a Reporting Services error saying the usual SQL Server error message...something like..."Cannot access SQL Server, make sure the server access remote connections blah, blah, blah"...but it did have the all important word: "rsReportServerDatabaseUnavailable" on it. I decided to Google that and found this post that fixed it.

Labels: , ,

Saturday, December 02, 2006

What is the UseSynchronizationContext property in WCF

The UseSynchronizationContext from the ServiceBehavior attribute in WCF is used to determine which thread your service will execute on.

Basically, if you have something like this on your service class at the time of creating your ServiceHost:

[ServiceBehavior(UseSynchronizationContext = true)]
class MyServiceClass: IMyServiceContract
{
// Implementation
}

then the value from the System.Threading.SynchronizationContext.Current is read and cached so that when a request comes to the service, the host can marshal the request onto the thread that the host was created on using the cached SynchronizationContext.

If you are familiar with the concept behind methods like Control.Invoke, Control.BeginInvoke() and Control.InvokeRequired() then you will be familiar with what the System.Threading.SynchronizationContext class is trying to achieve. Basically the SynchronizationContext.Send() and SynchronizationContext.Post() methods are similar to the Control.Invoke() and Control.BeginInvoke() methods.

If you try to host a service in, for example, a WPF application and also call that service from the same thread in the WPF application, you will notice that you get a deadlock when the client tries to call the service. The reason for this is that the default value of the UseSynchronizationContext is true and so when you create the ServiceHost on the UI thread of the WPF application, then the current synchronization context is a DispatcherSynchronizationContext which holds a reference to a System.Windows.Threading.Dispatcher object which then holds a reference to the current thread. The DispatcherSynchronizationContext will then be used when a request comes in to marshal requests onto the UI thread. But if you are calling the service from the UI thread then you have a deadlock when it tries to do this!!

Ive types this up pretty quick while its still in my head so hopefully it makes sense :-)

Labels: , ,