IIS 7 Worker Processes

Internet Information Services (IIS) Manager 7 includes a very nifty feature called Worker Processes. This feature will allow you to see information about the Worker Processes (w3wp.exe) for the sites running on the server.  If you’ve ever run Task Manager on your server and see several w3wp.exe processes killing your machine (high CPU usage), this is where you want to go. This feature will identify the Process ID of the Worker Processes and also tell you the associated application pool, very helpful in telling you which sites are killing your server.

You can also click into the worker process and view the current requests that are being processed, including the current requested url, client ip, and the time elapsed for the request. Again, very helpful information.

To access this feature, click on Start and then the Run command. Type in inetmgr to launch the IIS Manager Console. In the left pane “Connections” click on your server. On the right pane, you’ll have the feature view. There’s a section called IIS, and one of the last icons should be labeled, “Worker Processes”. Double click, and it will display all the current worker processes. Double click on a process and you’ll see the current requests. You can repeatedly click “Show All” to refresh.

SharePoint Error Delete Site WebDeleted.aspx File Not Found

We had several  users reporting an error when deleting a SharePoint team site. The error appears as a “File Not Found.” on the WebDeleted.aspx layout page along with a stack trace. It appears that the problem stems from our custom master page. For our implementation we use a custom HttpModule that redirects incoming requests for a master page to virtualized custom master pages that we maintain.

The WebDeleted.aspx page references the simple.master page which we redirect to our customized application master page. Apparently this results in the page trying to load in elements that are out of context for it. The solution was to stop redirecting simple.master and instead route it back to the SharePoint out of the box simple.master.

SharePoint CAML Query Date

For the past two SharePoint implementations that I’ve worked with, it was a common business requirement to query from a list to retrieve items that should be displayed on a “scheduled” basis. Think along the lines of an alert or announcement. Typically what I end doing is create a custom list and add the following three fields, “StartTime”, “EndTime” and “Active”. Start and End Time are the fields for scheduling the list item. I make them a Date+Time field and also allow them to be optionally be null, this way someone can create an open ended item that starts at a specific time but has no specified End Time. The Active field is a simple yes/no that is a convenient kill-switch or safety check.

So with the three columns, the following CAML query can be used to query items that should be currently displayed:

Determine if SPListItem belongs to a document library

So you have an instance of a SPListItem and want to know whether this item belongs to a Document Library or if it came from a list (such as an Event Calender, Survey, or Custom List). A quick way to distinguish a document library item is to access the ParentList property of the SPListItem class and examine the BaseType. In code,

SPListItem item = GetItemFromSomeWhere();

if (item.ParentList.BaseType == SPBaseType.DocumentLibrary)

{

// This item is from a document library – it probably contains a file.

}

SharePoint Custom Datasheet Mode – IE Crash

There is a known SharePoint customization bug that under certain circumstances, modifications to a master page (ie, use of a doctype or margin/padding) will cause the “Edit in Datasheet” mode to crash Internet Explorer.

The underlying problem is caused by a poorly written function called GCComputeSizing within Core.js The common fix is to override this function by defining your own function called GCComputeSizing in a script reference that is loaded in after the reference to Core.js is called in your master page.

However, what most of the other blogs and resources fail to mention is that Core,js can sometimes be loaded in using the “defer” attribute of the script tag. When this happens, core.js will now be loaded in after the page is loaded. Unless you also defer your override script, you will invoke the built-in GCComputeSizing function and the bug will persist.

This problem was specifically noticed when using user-defined or custom datasheet views. Comparing the source html for standard and custom datasheet view yieled the following:

Standard Datasheet View:
<script type=”text/javascript” language=”javascript” src=”/_layouts/1033/core.js”></script>

Custom Datasheet View:
<script type=”text/javascript” language=”javascript” src=”/_layouts/1033/core.js” defer></script>

As you can see, only custom datasheet views were loading in core.js  as a deferred script. Adding the defer attribute to our custom override script fixed this problem by deferring the override after the deferred core.js was loaded.

In terms of overriding GCComputeSizing  there are many examples easily searchable through the interwebs. One word of caution though, as a person who has quite a bit of experience with Javascript, GCComputeSizing not a function suitable for production. Even some of the *corrected* versions that others have posted still make me uneasy. Anything that has the potential of throwing a client’s browser into an infinite loop and locking up their cpu is a serious  cause for concern. Fortunately, our customized design uses a fixed layout so I was able to simplify GCComputeSizing to the following:

function GCComputeSizing(GCObject)
{
    if (TestGCObject(GCObject))
    {
      var lGCWindowWidth=663;
      var lGCWindowHeight=550;

      glGCObjectWidth = lGCWindowWidth;
      glGCObjectHeight = lGCWindowHeight
    }
}

SPListItem Url

So you need to get a url reference to a SharePoint list item? Use SPListItem.Url right?

http://www.sharepointsecurity.com/sharepoint/sharepoint-development/splistitemurl-funky-return-fiesta/

Useless SharePoint Error – SPQuery / Caml

Came across this error while trying to execute a Caml query through the SPQuery object:

One or more field types are not installed properly. Go to the list settings page to delete these fields.

Don’t believe it, you don’t need to delete any fields. You more than likely have a misspelled column or a column name that has a different internal name than what is publicly visible. For example, a default SharePoint calendar has a column field called “End Time”; however if you include the space within your query, you’ll get the error above. In this case, the internal name is really “EndDate”. Also look for column fields that have been renamed. Sometimes if you define a column, then later change its name – the internal name will still remain the same.

How are you supposed to know what the internal field name is? Well, here’s a tried and true method. Go to the list you are trying to query from, then click Settings -> List Settings. Scroll down to where all the Columns are defined. Click on the one in question, which will take you to the FldEdit.aspx page. Within your address bar, notice the querystring param Field. This references the internal field name for the column which you should also use in your queries.

SharePoint List Querying – Linq vs. CAML

One of the nice features of SharePoint 2007 development is the ability to use the latest release of the .NET framework and  its concomitant language features – including Linq. This in and of itself it a huge benefit as the inherit query mechanism within SharePoint – CAML is woefully terrible.

What is CAML? Officially, it stands for Collaborative Application Markup Language. Essentially, CAML is an xml structured intermediate query syntax for SharePoint to query against data structures (that can also be defined using CAML). Sounds a bit like SQL no? Well guess what CAML gets translated to in the back-end? Yep – SQL. SharePoint takes your CAML and queries against its sql backend. So in short, with CAML you have this massively verbose query syntax that requires nested xml tags, multi-line statements, and quoted attributes.

Enter Linq, with its terse sql-esque statements and amazing chainability. No more CAML!

Not quite.

Linq can only be used against a SPListItemCollection object which must be filled before use. The two most common ways to populate a SPListItemCollection is to either Get all items, or use a SPQuery object and CAML syntax to get a subset of items. As you can see, the dilemia presents itself that if you try to avoid CAML altogether, you will sacrifice performance when querying a list with potentially a large set of items.

So the best solution? Use both. Before using Linq directly to query items, first populate your SPListItemCollection with a CAML query that will do an adequate job of ensuring a manageable subset returned from the database. Then with Linq, fine-tune your SPListItemCollection to further sort and filter your result set. So Caml – Chainsaw, Linq – Carving Knife.

For more information, check out the excellent resource below:

LINQ and SharePoint Development: The benefits and the pitfalls

Outlook: Russian Spam

I’ve recently been flooded with a  flurry of Russian spam at work. Emails that are in all Russian that I have no idea what they mean. They usually get sent out past midnight so they’re queued up in my inbox by morning (smart, except for the fact that I can’t read Russian! – oh spammers…)

So how to get rid of them? If you’re using Outlook 2007, take the following steps:

Tools ->Options -> Junk Email…

Click on the last tab, “International”

And now click on “Block Encodings List…”

The following dialog appears…

Encoding List

Select Cyrillic for Russian characters, along with any other character sets you are unfamiliar with.

Click OK, then Apply.

Tags:

Empty Div With Width Displays Height in IE

I have a wrapper div that contains a user control that may or may not always display content. If it doesn’t have content, then the div should be empty and empty divs shouldn’t have any height right? Well, all the browsers agree with me – except Internet Explorer. Apparently since I’ve given this div a width, even though its empty, IE still decides to render height equivalent to the set font-size.

So can’t I just add a height:0; rule to my css? Well that will work – until the control within my div decides to render content and now its hidden.

So the fix? Add an html comment within the div. Yep, sounds crazy – but if your empty div is empty, save for an html comment, it will now not render any height.

Here’s how the fix looks like: