Nov 06 2009

Administrators! Stop before deploying that custom code!

Category: SharePointAlex Angas @ 6:53 pm

Even with no development knowledge, there’s a simple and quick tool that SharePoint administrators can run before deploying a solution package or web part to get some idea on whether it could cause instability your farm! It’s SPDisposeCheck and is particularly useful to keep an eye on the work done by a third party or even internally, with no developer knowledge whatsoever.

The tool was released by Microsoft in early 2009 to help developers check for memory leaks in their code. However there’s no reason why an administrator can’t do the same. Memory leaks can cause performance problems and general instability in your SharePoint farm. This tool tells you of any potential problems, and here’s how to use it:

  1. Download SPDisposeCheck and install. By default this will copy SPDisposeCheck.exe to C:\Program Files\Microsoft\SharePoint Dispose Check.
  2. Examine the deployment file you have been given. If this is a WSP file, rename its extension to CAB and extract all DLL files. SPDisposeCheck also works on EXE files if you’ve been asked to run a console application.
  3. For each DLL or EXE, run SPDisposeCheck using the filename as a parameter. To be assured of no SharePoint memory leaks, check that the “Total Found” line is 0.

Here’s an example that shows a potential leak:

SPDisposeCheckOutput

If the tool finds some issues then you should query this with the developers. However as the tool itself states, this doesn’t necessarily mean there is a leak! Unfortunately it can report false positives depending on how the code has been written. Regardless, make sure you have an assurance that the tool is run as part of their release process and any flagged issues have been checked. The tool will never miss a problem with a false negative.

It’s as simple as that. Be sure to add SPDisposeCheck to your admin toolkit and don’t let those developers get away with dodgy code!

Tags: , , , ,


Sep 29 2009

Query Demo Web Part

Category: SharePointAlex Angas @ 10:36 pm

A question recently came up on Stack Overflow about querying data from multiple SharePoint lists and binding the results to a GridView control. I realised there were some types of SharePoint queries I hadn’t explored, and that it would be interesting to compare them and see how they work in a web part.

Hence, I created the SPQueryDemo web part! It tests and displays results from the following types of queries:

  • For loop
  • GetListItems from Lists web service
  • SPQuery for SPList objects
  • SPSiteDataQuery for cross-site list queries
  • CrossListQueryInfo for cached cross-site list queries
  • PortalSiteMapProvider for SharePoint Server publishing sites only

Download it from CodePlex.

I’ve also used this project to try out using user controls for output rather than the traditional dynamic creation of controls in a SharePoint web part. This has been attempted with an MVP-style pattern which I’d really appreciate any feedback on.

In the future I’d like to add more functionality, particularly for different query options and types of queries. There is also an annoying bug when changing the query type where the page needs to be refreshed before changes take affect. If anyone would like to help or just check out the code, please download the source and hack away! You can also contact me via this blog post or via Twitter.

Tags: , , , ,


Aug 24 2009

When alerts don’t work ‘by design’

Category: SharePointAlex Angas @ 7:20 pm

I’ve just spent many fruitless hours trying to find a bug in my code that has been causing minor but visible pain for a number of users – and it was never even there. You would think after spending several years working with SharePoint I would know all of the ins-and-outs of alerts but not this one!

Scenario

  • “Require Check Out” is set to Yes (toggle the screenshot below in your mind, please!)
    Require Check Out
  • Alert created to only send when new items are added
    Send alerts when new items are added

Problem

User does not receive alerts on new items.

What’s happening?

When “Require Check Out” is enabled, alerts for a new document are only processed when it is checked in, and only the most recent alert event is kept. Here’s a simplified version of what SharePoint is doing behind the scenes when a user sets an alert for new items only:

Action Alert-related behaviour Response to user
User uploads a document “New item” event registered “Fill in properties and check in” page displays
User clicks “Check In” “Changed item” event registered and alert functionality triggered – most recent event is processed, sending a “Changed item” alert (“New item” event is discarded) Document checked in and user receives no alert

This is also an issue for users opting to receive alerts with the “All changes” or “Existing items are modified” options set. Their alerts will read the item has changed when actually it is new.

I asked about this on the SharePoint forums and received a good response from Lu Zou-MSFT confirming this behaviour. Unfortunately it’s unknown if this behaviour will change for SharePoint 2010.

Tags: , ,


Aug 05 2009

Showing the bulleted links list view

Category: SharePointAlex Angas @ 6:45 pm

A user recently took quite a shine to this lovely bulleted view of links in the list view web part:

Bulleted link list view

They wanted all of their existing links list to be changed over to use this view. What makes this case more unusual is that this is actually the view displayed as “<Summary view>” in the web UI:

Links toolpart

After much fighting with the SPViewCollection on the list, I discovered this post on Ketul Patel’s blog. He showed that to get a reference to this ‘hidden’ view, it is necessary to use the mouthy method SPList.GetUncustomizedViewFromBaseViewId(). The list view web part can then be changed to use the markup for the summary view. (Note that the web part needs to be re-added to the page so that the changes take effect correctly.) Here is a method that does this all this:

[csharp]
public static ListViewWebPart ReplaceWithBaseView(
ListViewWebPart listViewWebPart, SPList list,
int baseViewId, SPLimitedWebPartManager limitedWebPartManager)
{
string zoneID = listViewWebPart.ZoneID;
int zoneIndex = listViewWebPart.ZoneIndex;

SPView view = list.GetUncustomizedViewByBaseViewId(baseViewId);

ListViewWebPart replacementWebPart = new ListViewWebPart
{
Title = listViewWebPart.Title,
ListName = listViewWebPart.ListName,
Hidden = false,
FilterString = listViewWebPart.FilterString,
SuppressWebPartChrome = listViewWebPart.SuppressWebPartChrome,
ViewContentTypeId = listViewWebPart.ViewContentTypeId,
ListViewXml = view.HtmlSchemaXml,
ExportMode = listViewWebPart.ExportMode
};

limitedWebPartManager.DeleteWebPart(listViewWebPart);
limitedWebPartManager.AddWebPart(replacementWebPart, zoneID, zoneIndex);

return replacementWebPart;
}
[/csharp]

In order to call the above method, it’s simply a matter of getting a reference to the web part page and the web part. The magic number for “<Summary view>” is 0. Here is the calling code:

[csharp]
SPList usefulLinksList = web.Lists["Useful Links"];
using (SPLimitedWebPartManager webPartManager =
web.GetLimitedWebPartManager("default.aspx", PersonalizationScope.Shared))
{
try
{
foreach (WebPart webPart in webPartManager.WebParts)
{
if (webPart.Title == "Useful Links")
{
ListViewWebPart listViewWebPart = (ListViewWebPart)webPart;
ReplaceWithBaseView(listViewWebPart, usefulLinksList, 0, webPartManager);
break;
}
}
}
finally
{
webPartManager.Web.Dispose();
}
}
[/csharp]

Tags: , ,


Jul 31 2009

Explorer View breaks after IE8 install on Windows 2003

Category: SharePointAlex Angas @ 7:35 am

Since installing Internet Explorer 8 on my Windows Server 2003 development machine I’ve been unable to use Explorer View, with the error:

Please wait while Explorer View is loaded. If Explorer View does not appear, your browser may not support it.

Searching around, the main reasons seem to be:

  1. SharePoint site behind SSL – no fix at time of writing
  2. IE security level changes – fixable by adjusting security levels or adding SharePoint site to Trusted Sites zone
  3. WebClient service not running – fixable by starting this Windows service and ensure it is set to start automatically

For me the problem was #3, however attempts to start WebClient resulted in “File not found”-type errors. The following error was logged in the Event Viewer:

The application-specific permission settings do not grant Local Activation permission for the COM Server application with CLSID
{BA126AD1-2166-11D1-B1D0-00805FC1270E}
to the user NT AUTHORITY\NETWORK SERVICE SID (S-1-5-20).  This security permission can be modified using the Component Services administrative tool.

This familiar problem usually occursin SharePoint installations with the IIS WAMREG admin Service in Component Services. However this time searching the registry for the GUID in the error I had came up with the “Network Connection Manager Class”. Then searching for the GUID in its AppID key of {27AF75ED-20D9-11D1-B1CE-00805FC1270E} resulted in the netman component.

I then configured the security as described by the error in Component Services:

netman Launch Permission

After stopping and restarting MS DTC I was able to start WebClient successfully and Explorer View worked again.

Tags: , ,


Jul 29 2009

Debugging file locking in the GAC

Category: SharePointAlex Angas @ 9:25 pm

Do you ever find that your solution files have been “successfully deployed” according to SharePoint, yet the updated code isn’t taking effect? Perhaps you are trying to debug but breakpoints aren’t being hit when normally there’s no problem. Yet for some reason rebooting the server fixes the problem…

If that’s the case, the reason is probably file locking, most likely to occur if you have assemblies that need to be deployed to the Global Assembly Cache (GAC). If you ever find yourself in this situation, download a copy of the excellent Process Explorer tool, and follow these steps to verify:

  1. Start Process Explorer on the server affected.
  2. Press Ctrl+F, or in the menu click Find, Find Handle or DLL…, or just click the binoculars icon on the toolbar:Process Explorer toolbar
  3. Type the name of the assembly DLL and click Search.
  4. Under the Handle or DLL column, look for any assemblies located in the path C:\WINDOWS\assembly\temp. These lines tell you what process is locking the assembly.
OWSTIMER.EXE is the culprit

OWSTIMER.EXE is the culprit!

The C:\WINDOWS\assembly\temp folder is Windows’ equivalent of “assembly purgatory” where the assembly will sit until Windows can deploy it. If the currently deployed assembly cannot be overwritten as it is already locked by a process then the DLL will stay there until the process releases the lock or ends, or until Windows is restarted (also ending the process).

One example where this problem can occur is when a WSP solution containing custom e-mail event receivers is upgraded. The timer service, OWSTIMER.EXE, executes event receivers via the Windows SharePoint Services Incoming E-Mail job. As the OWSTIMER.EXE process isn’t restarted when a solution is deployed, it will always hold onto the lock for the DLL containing the event receivers. The solution is to restart the Windows SharePoint Services Timer service on each web front end server. If you’re finding this problem in development, WSPBuilder v1.06 adds a “Recycle the Windows SharePoint Services Timer” option.

This problem can also occur when using Visual Studio if certain combinations of add-ins are installed. You can again check this by using Process Explorer and verify if DEVENV.EXE is the locking process. If so, take a good look at the add-ins you actually need. Regularly restarting Visual Studio is very frustrating and will severely cut your productivity!

Tags: , , ,


Jul 28 2009

Gotchas configuring SSO

Category: SharePointAlex Angas @ 3:13 pm

SharePoint 2007 seems to have some real weirdness going on with configuring SSO. I’ve been setting it up in a test environment in a very simple way, using the farm administrator account for everything: Microsoft Single Sign-on Service account, Single Sign-On Administrator Account, Enterprise Application Definition Administrator Account, etc… Note that this is for testing only and is not best practice! Here are the problems I’ve found…

Weirdness #1: Error 0×80630005. Verify this account has sufficient permissions and try again.

Resolution: Log in to the server as the “Microsoft Single Sign-on Service” service account. As described by Frank Grossmann.

Weirdness #2: Error 0×8063064a. Verify this account has sufficient permissions and try again.

Resolution: Remote desktop to the server’s console (i.e. use mstsc /console) or physically log in to the server. As described by Dave Sobel. The Microsoft documentation for configuring SSO implies this but is not explicit:

Note that you must be logged into the SharePoint Central Administration Web site on a farm server to configure single sign-on (SSO) for Office SharePoint Server 2007. If you attempt to configure SSO on a workstation or any computer that is not a farm server, you will see an error message that reads “Single sign-on cannot be configured from this server. To configure single sign-on, go to the computer running the single sign-on service and specify these settings locally.”

I haven’t finished the configuration yet but hopefully there won’t be more problems. The best guide I’ve found is MOSS Single Sign On Setup Step-By-Step and beats what Microsoft provides.

Tags: ,


Jul 21 2009

“The rows you modified could not be saved to the server due to validation errors”

Category: SharePointAlex Angas @ 5:05 pm

Encountered a strange problem copying and pasting between the datasheet views of two contact lists. Only the Contact and Country fields were showing in the datasheet view.

When doing the paste, the following error appeared:

invalid1

The rows you modified could not be saved to the server due to validation errors. This is usually caused by invalid default values.

The error gives some clue as to the problem. I then attempted to add a single entry manually (without the paste) and received a new error:

Columns that require data are not included in this view. If you want to edit rows that are missing data in these columns, or add new rows, you must first add the required columns to the view.

Columns that require data are not included in this view. If you want to edit rows that are missing data in these columns, or add new rows, you must first add the required columns to the view.

Finally, I added all of the columns to the view and at last found the column causing the problem:

You must specify a non-blank value for Title.

You must specify a non-blank value for Title.

Setting the Title field to not be required fixed the issue!

Tags: ,


Jun 20 2009

Populate a SharePoint site collection from Excel

Category: SharePointAlex Angas @ 3:01 pm

I’ve needed to populate a site collection with many hundreds of sites in an automated fashion several times over the last couple of years. Every time the business owner gives me an Excel spreadsheet of the sites they want created. So rather than reinvent the wheel – again! – I’ve decided to start developing something reasonably generic and release it to my very first Codeplex project.

This first version is designed for a topology where each segment of the URL has its siblings in common. For example, Industry > Brand > Product or Division > Sector > Department. Depending on feedback I might make this more flexible.

Speaking of feedback, I’d really appreciate any comments from end users or other developers on desired features or comments on code WTFs! Please go to SPExcelator on Codeplex, download and add to the discussion!

Finally, special thanks to Robin Meuré for suggesting use of the excellent Excel Data Reader project.

Tags: , , ,


Oct 14 2008

Programmatically retrieving the name of an SSP

Category: Project Server, SharePointAlex Angas @ 3:51 pm

This was asked on the new Stack Overflow programming questions site recently (which you should really check out and start using if you don’t already!). Getting the SSP name is something that I’ve needed to do to build the SSP URL for impersonating access to the Project Server PSI. I used to think that the URL had to live in a config file. Then after some digging into Project Server’s behaviour with the help of Reflector, I discovered Microsoft use the SharedResourceProvider class in the Microsoft.Office.Server.Administration namespace. Who knows why, but this class is marked internal so reflection is required to access it, and therefore accessing it is not supported. We should be on relatively safe ground if MS products such as Project Server use it however…

The following code retrieves the name of the SSP for the current site collection.
[sourcecode language='csharp']
SPSite site = SPContext.Current.Site;
ServerContext serverContext = ServerContext.GetContext(site);

PropertyInfo srpProp = serverContext.GetType().GetProperty(
“SharedResourceProvider”,
BindingFlags.NonPublic | BindingFlags.Instance);
object sharedResourceProvider = srpProp.GetValue(serverContext, null);
PropertyInfo srpName = sharedResourceProvider.GetType().GetProperty(
“Name”,
BindingFlags.Public | BindingFlags.Instance);

string sspName = (string)srpName.GetValue(sharedResourceProvider, null);
[/sourcecode]

From there the URL to the PSI web services within the SSP directly becomes the following (and the port number is always the following on every server):
http://servername:56737/SSPName/PSI/ or

https://servername:56738/SSPName/PSI/

This does seem overly complex so if someone out there has a better solution please add it as a comment to this blog or update the answer on Stack Overflow.

Tags: , , , ,


Next Page »