Development

Get Central Administration Webapplication

With this code you can get the central administration webapplication. 1: private static SPWebApplication GetCentralAdministrationWebApplication() <span class=lnum> 2: </span>{ 3: SPWebService cS = SPWebService.ContentService; <span class=lnum> 4: </span> var service = cS.Farm.Services.GetValue<SPWebService>(<span class=str>"WSS_Administration"</span>); 5: SPWebApplicationCollection webApplications = service.WebApplications; <span class=lnum> 6: </span> <span class=kwrd>foreach</span> (SPWebApplication webApplication <span class=kwrd>in</span> webApplications) 7: { <span class=lnum> 8: </span> <span class=kwrd>return</span> webApplication; 9: } <span class=lnum> 10: </span> <span class=kwrd>return</span> <span class=kwrd>null</span>; 11: } If you have a better way, let me know 🙂

Control.ClientID has wrong value

An ASP.NET Controls has a ClientID property. SharePoint Controls inherit from the ASP.NET Controls. The property will give you the ID, the rendered control will have in the HTML source. There is one thing to remember: The ClientID is valid only, if the control has been added to the Controls of the Page! ID **before** adding the control ID **after** adding the control FilterButton **ctl00\_m\_Webpart1_**FilterButton So if you need the ClientID e.

New WSPBuilder version

Carsten Keutmann has released a new version of his great WSPBuilder. Here are the new features: A Reference folder under GAC and 80/Bin is now supported for large dlls that do not need reflection for SafeControls and Permissions. New menu function “Recycle the Windows SharePoint Services Timer” implemented on WSPBuilder Extensions. Refactoring of “Copy to GAC” in order to improve the functionality. Bug fixed! “Unable to get solution id from manifest: Unable to extract manifest.

Multi Level Navigation

The out-of-the-box WSS navigation offers one level of navigation. The navigation elements can be configured in the site settings. There is a way to make it have multi level navigation, as MOSS does, by changing the DataSource. But this “hack” is not flexible, as you can not reorder the item within the navigation menu. While I was reading the post How to create your own Cascading Navigation using the ASPMenu control, the decision was made to build a custom navigation which supports multiple navigation levels.

Using SharePoint Controls

Back from vacation. 1 week with an offline version of feeds is hard. So I read the postings I got closely 🙂 One post I do want to bring your attention to, is about SharePoint Controls. My post about using the SharePoint Controls shows how to use the controls you see in forms (TextField, NumberField, LookupField…). There are plenty of SharePoint controls, which you can use. Robin Meure has written a post “re-using SharePoint controls”.

.NET 3.5 and Silverlight

Using AJAX or Silverlight from within SharePoint in Webparts requires you to modify the web.config to support the technology. I don’t mention that you have to install the .NET Framework 3.5 SP1 and Silverlight to be able to use it… Instead of changing the web.config manually (.NET Framework 3.5 AJAX und Silverlight in SharePoint registrieren von Fabian Moritz), you can use my features. They do all the necessary changes for you.

SPQuery with lookup columns returns no data

An SPQuery for lookup columns should be easy. Start the famous U2U Caml Editor, configure your query, and query the list. This query will get a result if the lookup column stores something like “1;#1”. But if its value is e.g. “1;#Title”, the query will not return an item. So what can we do about it? Add a LookupId=’TRUE’ to your query, so it will look like this: <Where> <Eq> <FieldRef Name='LookupField' LookupId='TRUE'/> <Value Type='Lookup'>2</Value> </Eq> </Where> Remember to omit the Query tags from the U2U Caml Editor when pasting the query into your Visual Studio source code!

SharePointConsole Updated

My SharePointConsole has some new commands. If you don’t know it, it is a command line utility which allows you to perform some common tasks. Currently the theese commands are implemented: EnumContentTypes CreateContentType RenameContentType DeleteContentType DeleteAllListItems ShowInNewForm ShowInEditForm ShowInDisplayForm DeleteAllVersions RecycleAllVersions SetTitleWithFilename SetSearchCenterUrl SystemUpdate FeatureManager EmptyRecycleBin Download the SharePointConsole

Navigation for Wikis

The Wiki functionality SharePoint offers is great for quickly writing down stuff. It is often used for Server documentation. Creating new pages is easy, and you can link pages. The ability to format the text is nothing fancy, but most of the time enough 🙂 Uploading images can be done with my custom field type, which stores images and documents in existing libraries. After the upload, a link is inserted into the Wiki body.

Updated SDK

Microsoft has released a new version of the SharePoint SDK. Go and grab it 🙂 WSS 3.0 SDK Office SharePoint Server 2007 SDK So what is new in the release? WSS Expanded documentation of backup and restore features Complete documentation of Microsoft.SharePoint.Administration.Backup New documentation of the administrative object model Revised Web Part documentation More migration support Expanded and updated reference documentation MOSS Custom Federated Search Web Part with a Credentials UI Federated Search SQL Server Connector Federated Search HTML to RSS Connector Federated Search Virtual Earth Map Connector

How To get the default page from a website

This post is a follow up for my post “ Get default page Url”. When you access an SPWeb through a URL in your browser, you will be redirected to the default page like home.aspx. Each SPWeb has a RootFolder. And this SPFolder has a property “WelcomePage”. This property stores the relative path to the default page like “wiki pages/home.aspx”. 1: SPContext.Current.Web.RootFolder.WelcomePage

Summary: Common Coding Issues

The Best Practice MSDN page has some interesting hints to generate better code. In this post I write about some point of that article, provide samples and fix bugs which are in the MSDN article. Caching You should only cache thread safe objects. What’s that? This means, that you should only cache objects, which can not be changed from the outside of your code. An itemCollection (as list.Items) is changed, if another user adds an item.

Incompatible Web Part markup detected

For months the Webpart could be installed through a solution/feature without any problems. Then I had to change something in the code. When I tried to upgrade the solution to see the changes, the Webpart could not be added to a page anymore. The assembly is deployed to the GAC through the solution. It has been upgraded. Looking at the xml file in my solution did not show any errors.

SPWeb/SPSite.Dispose()

By now most of you should know that there is a SharePoint Diagnostics Tool. This really is a great tool, since it scans your assemblies for memory leaks. You should also know, that there is an occasion you can create a memory leak which the tool will not recognize. 1: using (var site = new SPSite(“http://yoururl”)) <span class=lnum> 2: </span>{ 3: SPWeb web = null; <span class=lnum> 4: </span> <span class=kwrd>try</span> 5: { <span class=lnum> 6: </span> web = site.