Workflow History List – Hidden

28 08 2008

Im currently working on some code in a SharePoint application page to write to the workflow history list programatically – from outside the workflow itself! I will post the details up when I get it working, for all of you who are trying to view your workflow history list as a SharePoint list, it does exist! it’s just hidden from view by SharePoint, simply use the following url with your own site:

http://servername/sharepointsite/lists/Workflow History

:-)!





Guitar Hero 3 – Rocks!

15 08 2008

Ive recently just aquired Guitar Hero 3 for the Nintendo Wii and it’s amazing. For any of you budding guitarists, rockers or just someone who likes their music I would recommend it. Amazon are offering it at the moment for only £39.99! It comes with a Les Paul replica guitar controller, I at first thought it would be wierd playing a plastic guitar, after all I do play the ‘real’ thing also. But I was wrong, it’s great fun and when you finish a song without missing a note its very rewarding. So get a copy, strap your guitar on and get rocking!





Useful List of SharePoint List Template ID’s

14 08 2008

While searching for the List Template ID of an XML Form Library, I found this very useful list of SharePoint List Template ID’s at Simeon’s blog, so thought i’d share it: http://simeonlobo.wordpress.com/2008/02/27/sharepoint-list-template-ids/

Alex





Creating a Simple Event Handler for SharePoint – Part 2

12 08 2008

In the last post we created the dll for our event handler, we now need to deploy this event handler as a feature so we can use it on our SharePoint lists.

Create a blank visual studio solution, it does not matter which project type you use (i would recommend a class library project). In your new project, add a new folder called ‘DeletingEventHandlerFeature’.

Within this new folder, create two XML files – one called Feature.xml and the other called Elements.xml.

Your solution explorer window in Visual Studio should look like this:

The feature.xml is the xml file which defines the feature itself, open the feature file and add the following code:

<Feature Scope=”Web”

Title=”Deleting Event Handler”

Id=”ENTER A GUID HERE”

xmlns=”http://schemas.microsoft.com/sharepoint/”&gt;

<ElementManifests>

<ElementManifest Location=”Elements.xml”/>

</ElementManifests>

</Feature> 

Be sure to enter a unique GUID into the ‘id’ attribute by generating one from within Visual Studio. The elements.xml file will call the dll we created earlier and will specify the type of list that the event handler will attach to. In order to tell the feature the details of the dll it is using, we need to get the assembly and class name of the dll we created in part 1, I would recommend a program called the .NET Reflector to do this – http://www.aisto.com/roeder/dotnet/.

Enter the following code into the elements.xml file, replacing the <assembly> and <class> with the details of your dll:

<Elements xmlns=”http://schemas.microsoft.com/sharepoint/“>

<Receivers ListTemplateId=”101″>

<Receiver>

<Name>DeletingEventHandler</Name>

<Type>ItemDeleting</Type>

<SequenceNumber>10000</SequenceNumber>

<Assembly>DeletingEventHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=81323876ac0307e0</Assembly>

<Class>DeletingEventHandler.DeletingAction</Class>

<Data></Data>

<Filter></Filter>

</Receiver>

</Receivers>

</Elements>

In order to specify the correct list type to attach to, change the Receivers ListTemplateId accordingly, to see a full list of SharePoint list types, visit the following url: http://msdn.microsoft.com/en-us/library/ms431081.aspx.

Now we have created our feature, we must deploy the dll to the GAC (Global Assembly Cache) and install/activate our feature. Log on to your SharePoint web front end server and copy the dll created in Part 1 to ‘C:\Windows\Assembly’, this will install the dll into the GAC.

Copy the folder created in your visual studio project to the following folder on your SharePoint server: ‘C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\FEATURES’, you can use an XCOPY command at the project debug time if you wish.

To install the feature, you will need to use the SharePoint ‘STSADM’ admin tool, run this from the command line with the following switches:

To Install:

-o installfeature -name DeletingEventHandlerFeature

To Activate:

-o activatefeature -name DeletingEventHandlerFeature -url ‘Site URL Here’

Once you have run these commands, be sure to do an IISRESET, the event handler should now be attached to lists of the type which you specified in the elements file, it will also be attached for all future lists of that type that are created.

🙂





Creating a Simple Event Handler for SharePoint – Part 1

12 08 2008

A question often asked by my users was can we prevent other users from deleting or modifying their documents uploaded to a document library, this as we all know is core SharePoint functionality but can be disabled by using event handlers.Event handlers bind/attach to document libraries or any type of SharePoint list and fire a particular piece of code when a specified event occurs. Their are many different events, such as:

ItemAdding – Occurs when an Item is being Added

ItemDeleted – Occurs once an Item has been Deleted

So you see, we can fire our code before the event happens, or after if required.
In this post, we will create a simple event handler for the ‘ItemDeleting’ event so that when a user who is not the creator of the item goes to delete the item they will be presented with an error message.
1. Create a new project in Visual Studio (2005 or 2008 up to you) and select a Class Library (C#)

2.Rename the .cs class file to something suitable and enter the following code:

public override void ItemDeleting(SPItemEventProperties properties)
{
//Declare our Variables
string currentuser;
string creator;
//Set up our SharePoint List Item
SPListItem rfq = properties.ListItem;
//Get the Display Name of the Current Logged In User
currentuser = properties.UserDisplayName.ToString();
//Get the value of the Created By Field of the current item
creator = rfq[“Author”].ToString();
//Convert the Author into a SharePoint user id
int userid = Convert.ToInt32(creator.Substring(0, creator.IndexOf(“;#”)));
//Get the SharePoint user which matches the ID
SPUser user = web.AllUsers.GetByID(userid);
//Set the domain login name of the author user
creatorname = user.LoginName;
//Compare the two user names to see if they match
if (creator == currentuser)
{
 //Allow deletion of the item

properties.Cancel = false;
}
else
{
//Cancel the Deletion of the item
properties.Cancel = true;
//Raise our Error Message to the user
properties.ErrorMessage = “You are not the creator of this item therefore you cannot delete it.”;
}

 

 

 

4.Next we must strongly sign the assembly, so go to project > properties within visual studio, go to the signing tab and click ‘new’, give it an appropriate name and select OK.

Your Solution Explorer should now look like the following:

5.You can now debug the solution to build the dll.6.So how do we install this into SharePoint I hear you all ask?, well stay tuned for Part 2 of this tutorial where I will show you how to use ‘features’ to install the event handler into SharePoint.




My First Post

12 08 2008

Welcome to my blog,I have created this to help share some of my experiences and knowledge of the Microsoft Office SharePoint Server (MOSS) Environment. I hope to update this blog daily with coding examples, tips, tricks and help on SharePoint administration.