06.26.09
Posted in General, Programming, SharePoint at 8:20 am by Reginald
Ok, well I think I’ve worked out why the GUId isn’t getting defined.
The code I’ve written creates an EventHandler on the base content type. When this content type gets assigned to a library, the content type is instanced to the library and as a result I think the GUID i assign is removed.
I think were I to assign an event handler directly to a list, then this wouldn’t be the case and I could give a GUID in the creation method.
I’ve not tested this yet, but it seems to make sense.
Paul.
Permalink
06.23.09
Posted in Programming, SharePoint at 8:17 am by Reginald
Eek.. June already.. I’ve been on my hols, come back and realised that I’ve been somewhat remiss in posting to my blog.
So without further ado, I’ll talk about my current expedition into the realm of SharePoint code. Todays task is EventHandlers from code.
Attaching Event Handlers from code is pretty easy, the SDK shows various methods all of which seem to do the trick. However, I want my Event Handler to have a specific GUID as it’s ID. The idea behind this is that my management application knows what the different event handler ID’s are in all the environments.
And this is where my plan has currently fallen apart.
I’m using the following code to add the event handler (after correctly checking that an event handler of the same name and assembly doesn’t already exist of course..)
if (!itemDeletingExists)
{
SPEventReceiverDefinition deletingReceiver = erdc.Add(new Guid("F649A610-2C83-4f11-B73F-A7D1656DEACB"));
deletingReceiver.Name = "ResourceEventsItemDeleted";
deletingReceiver.Type = SPEventReceiverType.ItemDeleting;
deletingReceiver.SequenceNumber = 10000;
deletingReceiver.Assembly = assm;
deletingReceiver.Class = nsp;
deletingReceiver.Update();
receiverAdded = true;
}
When you step through the code above, the event handler is added quite happily and the deletingReceiver.ID = the guid used in the constructor.
So further down my code we grab the collection of event handlers currently held by the content type and sure enough, there is our (in this case 3 of them) event handlers, sitting happily in the collection.
However, if you grab the EventReceiverDefinition for each of them, the .ID is all zeroes… Is this a bug or intended behaviour? Further investigations ongoing..
Paul.
Permalink
05.07.09
Posted in JQuery, Javascript, Programming, SharePoint, Uncategorized at 11:36 am by Reginald
So in an earlier post I talked about using JQuery to remove the A tag that is automatically included in the rendering of a linked list item in display mode.
I really liked this solution as it avoided having to go to the lengths of writing a custom field to solve this and can be targetted at a single page, or a whole site by embedding the code in the Master Page.
So, anyway, it’s worked quite nicely at the client that instigated the investigation, so I decided to re-use the code for a new client. This has functioned perfectly, right up to the point where they used a list view with a Group by in the selected view.
So, why does this cause different behaviour? Well the answer is in how the ListView web part handles the hiding and revealing of the grouped data. When you click on the expand link, the page performs a partial postback to SharePoint to get the missing data, before returning a block of HTML to display.
As this happens during the partial postback, the already registered code on the page doesn’t run a second time as the jQuery event $(document).ready doesn’t trigger again.
I tried various methods before placing a post on the EndUserSharePoint.com StumpThePanel Q&A forum in the hope that “JQuery in SharePoint” god Paul Grenier would be able to answer my timing issues, which he did very nicely!
So how did we resolve it.. The answer is to replace the MicroSoft function that handles the posted back data within the listview ExpGroupRenderData() with a JQuery version.
function ExpGroupRenderData(htmlToRender, groupName, isLoaded) {
$("#tbod"+groupName+"_").attr("isloaded",isLoaded)
.html(htmlToRender)
.show("fast",HideLinkedListItems());
}
HideLinkedListItems() is the previously created function to strip the A tag frm linked list items, wrapped in a function wrapper so that it can be called frm either the update, or the Document.ready as per the original post.
The result, expanding the listview now presents the list view items, nicely stripped of their links.
I hope this helps someone achieve the same..
Paul.
Permalink
04.22.09
Posted in Javascript, Programming, SharePoint, Troubleshooting at 2:30 pm by Reginald
A client of mine recently required adding an additional E-Mail link adding to the Item Drop Down menu that drops off of the ECB menu within Document Libraries and Lists.
Now this functionality is provided by the function AddSendSubMenu(m,ctx) within Core.JS. Editing this file is NOT SUPPORTED (You all know this by now I’m sure!). So what to do? Well the answer is make use of Javascript’s natural override.. I.e. If you declare a function twice, the last declaration is the one that gets used.
So, Seems simple huh? We copy the function we want out of Core.JS and stick it into our own NewSendToMenu.js file in /TEMPLATE/LAYOUTS/1033
We then place a standard little script tag into the Head of the Master Page and bobs your uncle, the code gets loaded quite happily on each page.
Or does it? Well yes it does always get loaded.. I proved this by putting a document.write(”Hello World”) in front of the function and this got displayed every time without fail, And yet my customisations weren’t there.
I remembered reading somewhere that Core.JS has a habit of hanging around and getting executed last, My original method using the SharePoint:ScriptLink tag seemed to support this, so I dropped back to using the standard Script tags.. same problem though..
I then stumbled across a small article on the MSDN forums that pointed out the use of the Defer tag in the Core.JS script block. (You can see this if you view the page source in IE..) This means that the execution of Core.JS is deferred until the rest of the page is loaded, thus overriding my own override..
So the solution appears, Declare my script lower down the page than the Core.JS, and tag my Script block with the Defer option also.. This appears to execute my code AFTER core.js has completed.
Now, I’m not 100% how often this will be the case.. looks like this may need some load testing, but I think it’s fair to say that if one script is deferred higher up the page, than another lower down, they should be deferred into the same execution order that they met during page load?
Or am I being too simplistic? Never mind.. for now this works and resolves the client issue!
Paul
Permalink
04.17.09
Posted in Installation, Laughter, SharePoint, Win2K8 at 10:49 am by Reginald
Ok, yesterday was not my best day.. There’s a reason that I switched from ITPro to Dev.. Dev’s shouldn’t do installations as they forget the important bits..like logging in as the Site Collection Admin into Central Administration, and not the Farm Admin..
Logged in properly this morning and hey presto, there’s my create or extend option….
DOH!
Permalink
04.16.09
Posted in Installation, SQL2K8, SharePoint, Win2K8 at 4:02 pm by Reginald
Ok, so today saw me startto build my development environment for those clients that have switched to Windows 2008 and SQL 2008.
All told, I have to say the install for both products is pretty slick, I think for Win2K8 I probably clicked about 6-7 times before I had a fully working server installed and running in the VM.
Installing SQL onto that was just as simple, I opted for Standard edition and installed only the Database engine.
So onto installing WSS itself. Microsoft have published some installation papers to fllow when installing onto Windows 2008, and I have to be honest I didn’t follow them for gospel..Afterall I’m a developer.. when do we RTFM? That’s right..when things go wrong..
Guess what.. It’s starting to go wrong..
SharePoint installed absolutley fine, no errors.. A few minutes later, the infrastructure update went on top… All fine, the configuration database updated happily..
Well this is all dandy.. Up pops Central admin, so I figure I’ll create a quick Web Application and check that I can browse from my desktop to the VM to see that IIS/Win2K8 security is all happy.
Hmm.. Hang on.. where on earth is the option to “Create or Extend a web application”..? It’s just not there.. Todd Klindt suggested to me on Twitter to make sure that I’ve used the Admin Tools option, rather than just browsing, which I tried as well.. The Bamboo community forums suggest running Internet Explorer as administrator.. I did that too..
But at the moment, nothing seems to work.. I’m going to try that old faithful now.. A reboot!
Paul.
Permalink
04.14.09
Posted in General, JQuery, Programming, SharePoint at 2:30 pm by Reginald
A client of mine recently raised a concern about the linked list items that are used within SharePoint. In the display list view, they show up as hyperlinks to the linked item. All well and good, you can click on these links to see the full item, however there is no easy way to return as when you click on close you are sent to the default view for the list the linked item belongs to.. (Still with me?)
We discussed several ways around this, but the feeling from the client was that they didn’t want to see these links anyway, so removing them would be the best solution. (I did suggest creating a whole new field type with the option to turn off the Hyperlink in the display render, but they felt that was overkill)
Having played with JQuery, I was pretty certain that we could override the default behaviour using a simpler jQuery selector.. But what do we select?
Well the Linked List items very handily all have the term RootFolder=* in their URL. No other link in SharePoint appears to have this and certainly my testing hasn’t thrown up any errors yet!
So, how do we remove this link in jQuery? Well the trick is to return a collection of A tags that have an Href containing the pattern “RootFolder=*”. Once we have this, we simply add a sibling node using the .After() function to create a new span tag, and then copy the previous tags text content into the new tag, before hiding the A tag using .Remove()
It sounds very simple and it is, but as I found during this exercise, the secret is getting your selectors spot on and making sure the code is firing properly!
Paul.
Note: You will need to have downloaded the JQuery library and registered it in the masterpage, along with the code below (Which can either go in a Content Editor Web Part, or be placed in the Masterpage itself if you want to affect every page.)
<script type="text/javascript" src="/jquery-1.3.1.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('a[href*="RootFolder=*"]').each(function(index) {
var link = $(this);
$(this).after("<span>" + link.text() + "</span>");
$(this).remove();
});
});
</script>
Permalink
Posted in Uncategorized at 7:56 am by Reginald
Well last week saw the first European SharePoint Best practices conference organised by Combined Knowledge here in London.
The event, located at the QEII Conference centre in Westminster was exceptionally well run by Combined Knowledge, Steve and the gang certainly know how to run a user event and all of the staff from CK and the red coats were exceptional. Zoe as always had all the information needed to hand and is my personal favorite for saving me from the Headache from hell!
As to the sessions themselves, I followed the dev track religiously as there are several areas that I’ve been keen to improve on.
The first session featuring the somewhat ‘manic’ Todd Bleeker was exceptionally entertaining and enlightening and set the scene for the conference to come. Todd manages to bring his love of SharePoint and desire to spread the word of development joy to the world with the enthusiasm of a Baptist Revival Minister. A throughly engaging man, I had the pleasure to spend an hour during one of the sessions with Todd showing me how to use his none ajax method of preventing full page post backs using the ICallBackEventHandler, something that I will be making use of in some of my webparts this very week to fully understand it.
Further sessions from such well known US based speakers as Andrew Connell (on Field controls and webparts in publishing sites, Star Wars references were a hoot!!), Eric Schupps (on Custom Site definitions and High Performance applications.. I used a method from this at a client last week and decreased page load times by 20%!)
And our very own home grown talent in the form of Chris O’Brien (Deployment methodologies), Andrew Woodward (TDD and SharePoint in education) and Ben Robb (Customising the Search UI)
And the final sessions of day 2 and 3 were the open mike Ask the Experts panel. Judging by the comments received from people in the other sessions, ours was the best attended and certainly the most fun. Each of the speakers were happy to be challenged by the audience and I gained an great insight into some of the subjects discussed.
Overall, for my first ever Conference, I found this event to be possibly the most value for money training event I’ve attended, with a great return on investment!!
Regards
Paul.
Permalink
03.04.09
Posted in General, Programming, SharePoint, Visual Studio 2005 at 11:51 am by Reginald
The Microsoft SharePoint team have released a SharePoint disposal checker tool to the MSDN community. This command line tool scans individual asseblies, or entire directory structures and analyses the code for memory leaks through poor disposal.
I ran it against some of my assemblies and I’m happy to say only my quick command line tools written for testing exposed any poor disposal issues.. (Mainly because I don’t bother worrying about disposal when I’m just testing constructs..)
The project site can be found here with further links to the team behind the tool.
http://code.msdn.microsoft.com/SPDisposeCheck
Reg.
Permalink
03.03.09
Posted in General, SharePoint at 8:56 am by Reginald
One thing that has always confounded me is the lack of a breadcrumb in List View WebParts.
Picture the scenario, You drag a Document library list view onto your web part page. fine no problems there. You click on the first folder, down one level, then another, Then perhaps one more.. Hang on, I thought folder structures should be a thing of the past? Ah well, the document I want isn’t here, I’ll go back up a level.. (I should have used searched shouldn’t I?).
Hang on.. how do I get out of here.. help.. let me go back up a level..I can’t.. I’m stuck!!!!!!!!!! Waaaaahh.. Page reload.. ah I’m back at the top, all calm again…
So how do we get around this problem? Well in the first instance, lets avoid the use of folders where possible, but in some implementations, it’s just not possible, afterall, users are familiar with the concepts of folders and hierarchical structure.
This was the problem set to me by a client recently and solving it is a quite interesting problem that I’m part way through solving.
So I have two approaches, the first one is brought about by the realisation that when you place the list view on a publishing page, and drop down a folder level, a querystring is placed into the URL that shows the current folder location. Fine, we can probably parse that out and use the locations to create a breacrumb, but for some reason it doesn’t root itself in the library itself, but the parent of the website itself.
E.g. http://website/sub-web/Forms/Forms Library/First folder with the querystring showing /sub-web/Forms/forms Library/First Folder (Note: Both sub-web and forms are websites within a publishing collection.)
So not perfect, Also, what happens if we have mroe than one list view web part on the page? (I’ve not investigated that one yet..)
The second option is to get a connection into the Page WebPart manager and see if we can find out any information on the current folder from the List View Web part itself.. The jury is out on this one..
So watch this space for some code very soon..
Reg.
Permalink
« Previous entries