A place for Sharepoint and rantings
Sharepoint
WSS3 – ItemAdded – deadlocked on lock
Feb 12th
I’ve been having a problem with an app I wrote. It works great, 99% of the time, but sometimes the ItemAdded event appears not to fire.
Now this is using a list with over 20,000 entries in it and its growing all the time. An associated list that references this list as a lookup has over 144,000 entries in it.
The event firing problem is becoming more frequent now as more users start using the system, there are at least 20 occurances in that 20,000 items, so it has to be fixed.
Managed to track down an error in the log
System.Data.SqlClient.SqlException: Transaction (Process ID 61) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction.
It’s stack trace was similar too this (I cut it down a bit and changed some names, my naming is not this bad)
at Microsoft.SharePoint.SPListItemCollection.EnsureListItemsData() at Microsoft.SharePoint.SPListItemCollection.get_Item(Guid uniqueId) at BinaryJam.Core.Code.TicketListReceiver.ItemReceiver.ItemAddedActual(Guid SiteId, Guid ListItemId, String UserDisplayName) at BinaryJam.Core.Code.TicketListReceiver.ItemReceiver.<>c__DisplayClass11.<ItemAdded>b__e() at Microsoft.SharePoint.SPSecurity.CodeToRunElevatedWrapper(Object state) at Microsoft.SharePoint.SPSecurity.<>c__DisplayClass4.<RunWithElevatedPrivileges>b__2() at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElevated secureCode) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(WaitCallback secureCode, Object param) at Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(CodeToRunElevated secureCode) at BinaryJam.Core.Code.ItemListReceiver.ItemReceiver.ItemAdded(SPItemEventProperties properties)
So as you can see, it explodes on the GetItem.
This was my stupid mistake, More >
WSS, Workflow, Who Actually approved this ?
Nov 5th
So I like many have a workflow that takes requests for Sites with a bunch of details for costing etc. Then when approved those Sites are created and permissions allocated.
What we did not have was a record of who actually approved the sites. Whilst this info is in the workflow history after a while that information gets purged, leaving us with Sites that were approved but by whom we know not.
So this is a simple case of changing the workflow and recording all of the approvers in the SPWeb properties, except that the approvers as we can tell happen to be Sharepoint Groups or AD groups, neither of which contain a history of membership, if AD does none I know how to access and certainly not easy for the customer and in a large membership we still would not know who actually did the deed.
I dug and dug for this and eventually found the User Login that actually did the change and here is how.
In your workflow you need a “Workflow Action” of EventName “OnTaskChanged”, this object in the code behind, when Invoked contains AfterProperties,
string user = OnApprovalTaskChanged.AfterProperties.ExtendedProperties[new Guid("d31655d1-1d5b-4511-95a1-7a09e9b75bf2")].ToString();
The above statement gets the User Login frmo the ExtendedProperties Collection. It More >
Sharepoint and ResX and a little tool
Oct 14th
I am doing lots of work in Sharepoint that requires resource files in english and german.
With a variety of developers before me different styles of editing the foreign language files emerged.
I think that much better tool support for managing resx’s is required, and I recently found one that is a great help to us with a vareity of resx’s in various states of translation and existence.
http://resxtranslator.codeplex.com/
This resx tool allows you to pick a file and it displays the nuetral and foreign side by side along with comments and allows you to edit them all at once. Corking piece of work, some polish would go amiss but Im hard pushed to say where as it does exactly what I need it to do and I can pass it to a non-techie developer. It still down to me to edit the comments first to identify what needs translating and what definately needs leaving alone.
If you doing multi-language work go and check this tool out it might just help.
WSS and PowerShell 2
Jul 31st
If you were one of the two people who read my last post on WSS and PowerShell I updated it a bit and it’s worth checking out the changes.
I thought this time I would just point out some of the very simple statements in PowerShell that differ from your usual C# so that you can quickly make a transition from one to another.
One of the first things any programmer might need to do in a script is conditions so here is a PowerShell condition and how it differs to c#
if ($i -eq 10) { write "It's ten you know" }
The comparison operator for equals is not "=" or "==" but a scripting style operator of -eq. So this is the first thing you’re going to have to remember. Other operators are
-gt greater than, -lt less than, -ge greater than or equal to, -ne not equal
There are more I found a simple table of them here.
When dealing with boolean responses its important to know that they are represented by $true and $false so a condition to test this would look like
if ($kidding -eq $false) {
write "How strange" }
Now being good little programmers you’re bound to want to structure your More >
WSS3 Event Receivers
Jul 23rd
I’ve been doing some work with List Item Event Receivers and thought I’d share my experiences.
First there are a bunch of events that can be raised, I won’t list all but here are some of the good ones
ItemAdding / ItemAddedItemUpdating / ItemUpdated
There are also specific ways of dealing with the data in each of these events, those that are “ing” events then the changes have not been applied yet so you get the change values from the AfterProperties passed in, those ending in “ed” you can grab the List Item directly as changes have already happened.
My experiences have been problematic so here is a few points that may help you when using these events.
AttachmentsIf you want to get hold of the attachments being added to a List, you can’t. (This may differ for doc libraries I have not inspected this). Attachments are not on the list item as it does not exist yet and they are not in the Properties either. Anything you want to do regarding attachments you have to do in “ed” events.
ID’sWhen in the “Adding” event the one thing you have not got is the List.ID value. If you were hoping to create entries in More >
WSS and PowerShell
Jul 23rd
The more I do with SharePoint the more and more I an finding a use for PowerShell. I am using WSS as an application platform and using lists etc as a datasource. Providing what you want is not huge amounts of referential integrity and transactional control etc it works pretty well.
But when things go wrong, often the only way to quickly get in a fix something in a structured, repeatable and documented manner is PowerShell. Hell and its fun too.
So as a Sharepointy person what do you need to learn to get you quickly started.
First go and install PowerShell, this is version 1 which is what I am using, version 2 will be great but is not in production yet, so try getting that on your live servers, if they let you, sack them – pre-release code on production servers pah!.
Next go and download Quest’s PowerGUI. This comes with the fantastic script editor, that allows stepping through code and debugging, i tend to use this for all my PowerShell development, I’m used to Visual Studio so being confronted with a command shell environment can be a little daunting.
Now if you go looking on the web at powershell there are More >
WSS 3 – Site Provisioning / List Security
Jul 13th
I’ve been having some more fun with Site Provisioning. I have a requirement that in my Prov code I need to alter groups. For most of my work I’ve been altering RoleAssignments in SPWebs with no trouble, however I came to do the same with a list as in an SPWeb.
Now I’m not sure if you can do security in the ONET but for my requirements I have $Resources that need concatenating together to form the group names (don’t ask). Which it can’t do so it has to be done as a site provisioning thing.
What I noticed though is in my list, "of parent SPWEb of Parent SPWeb(RootWeb)" things where not as they were supposed to be.
The security on the list was completely wrong, as in it stated it had Unique permissions, when actually it does not, it will have when I’m finished with it, but at Site Provisioning time it should not. Also all the groups were relating to the Site Collection level not the custom groups of the sub site it should have inherited.
It’s as if none of the list processing for fixing up the security on the list has happened, as it had done previously on SPWeb More >
Sharepoint Versioning – Gotcha 2
Jun 10th
I’ve had a right game with this Sharepoint Versioning problem.
Now those of you used to writing .NET but maybe not SharePoint will be used to having AssemblyVersion attributes set in the AssemblyInfo.cs files.
This is something I took into my last SharePoint application for wss3. Now in SharePoint 2003 I got used to not setting the version number but it slipped my mind for WSS 3.0.
My particular problem was I had some ItemAdding/Updating List events. These were configured to fire in one of my Assemblies. My build server would automatically increment version numbers in AssemblyInfo.cs and in all associated .xml files in the features, very clever I thought at the time. Now I needed to update this assembly and modify some code in these events.
I made those changes and installed it and all of a sudden none of the events were firing at all.
This is because when a list is created the EventReceiver details of the feature are not read from the XML file but are stored against the List in the content database. This makes some sense as if you update the list template then you can update the EventReceivers as well and have different versions of a list definition More >
SPUtility.SendEmail Function truncates text
Feb 10th
It would appear that
SPUtility.SendEmail function truncates the body of the email. I’m having this problem and so is someone else (here).Not much more to add here, if anyone knows why or knows of a setting, love to here it
(please don’t post a workaround solution using .Net objects we can all figure that one out for ourselves thanks.)
Word of the day.
Damn.
Technorati Tags: sharepoint,wssWSS – CAML and XSD schemas
Feb 10th
If you developing List Schemas drop what your doing and go and install this.
It is an expanded wss.xsd file containing a lot of descriptions and possible default values. When coding in Visual Studio using this will alter the schema defs and give you uber intellisense on your schema files.
If you already use wss.xsd in Visual Studio you will need to remove your reference.
Now if you forgot how you did that then the usual way I found of configuring it was to goto
C:\Program Files\Microsoft Visual Studio 8\Xml\Schemas
(or equivalent for your platform)
An to create a file called wsscatalog.xml, you may have called it something else but it contains xml like this
1: <SchemaCatalog xmlns="http://schemas.microsoft.com/xsd/catalog">
2: <Schema href="%CommonProgramFiles%/Microsoft Shared/web server extensions/12/TEMPLATE/XML/wss.xsd"
3: targetNamespace="http://schemas.microsoft.com/sharepoint/" />
4: </SchemaCatalog>
So go and remove that before installing this version as it won’t remove it for you and Studio can fight over things if you don’t or just not work at all as was my case.
Technorati Tags: wss,visual studio,caml,intellisense