Monday, October 22, 2007

Output Caching

In the next three posts or so I will be covering the types of caching available in ASP.Net 2.0 and MOSS. The first of these three types is output caching. Output caching is the ability to render a page once and then store the HTML output of that page in cache for a set period of time. Each user (and I use this term fairly loosely for caching; I will explain in a little bit) that hits the page after it is cached will receive the cached page. The output cache caches a page based on type of user, either authenticated or anonymous, and by the type of browser. Yes, out caching stores each page for each browser type, so the Mozilla rendering of a page will be separate than the IE rendering.

This type of output saves both on processor speed and the number of round trips to the database which can be pretty slow depending on your MOSS configuration.

Thus type of caching is only available if you have the MOSS Publishing Infrastructure feature enabled. If your site is built on the Publishing Portal or Collaboration Portal then you have this by default.

Go to Site Actions - Site Settings - All Site Settings and go to Cache Profiles to set up the profile and its settings. You can have profiles for different types of users, one for anonymous, or one for authenticated users.

You need to give the profile a title and you can give it a display name and description. You can then check the checkbox for Performa ACL check. This will check for security trimming when caching. If you do not need security trimming then uncheck the box to increase performance.

You then need to check the box labeled Enabled to enable the caching on that profile. This check box allows you to easily trouble shoot a profile by enabling and disabling in one click.

You then set the duration to hold the cached pages before re-rendering the page. This number is in seconds. A good rule of thumb is to start at about 2 hours and check the performance of your server and adjust the cache duration accordingly.

The Check for Changes box if checked will check to see if the page has been changed. If it has it will re-render the page and store it in the cache. If the page has not changed then the cache will be used. If you check this box it will decrease performance as the site now has to check each page for changes before it renders the page.

You can then choose to vary the cache profile based on custom parameters, HTTP headers, query string parameters, or User rights. For most people you can leave the defaults that come with the base profiles.

Cacheability defines where the page gets cached and is one of the following: none - the page is not cached, server - the page is cached on the server, private - the page is cached in the browser, server and private - the page is cached at both the server and the browser.

The last two check boxes allow for caching for authenticated users and for contributors.

After you have created the profile you then need to enable the caching and select which profile to use for both anonymous users and authenticated users. There are also some check boxes on this page to allow sub-sites and page layouts to override the caching of the rest of the site. This can come in handy if there are a couple of pages that render code differently depending on a selection. You may need to turn caching off on that page layout for the page to render correctly.

You can also enable debugging information in the pages. This is handy to test whether pages are staying in the cache and to make sure they are staying in there for the entire duration time. This will place a timestamp on the very last line of the HTML source that will give you the profile that rendered the cached page and what time and date the page was cached.

Caching requires a lot of fine tuning for performance of your server or server farm. Dedicate the time, though, and your site will run smoothly and scale easily.

Here is a wonderful article on performance tuning and caching that will aid you on your journey:

http://blogs.msdn.com/ecm/archive/2006/11/08/how-to-make-your-moss-2007-web-site-faster-with-caching.aspx

In the next post I will explain object caching and how to track it.

Labels: , , ,

Sunday, October 14, 2007

When a Cache is Not a Cache

The first problem area I had with our project was when we made the Internet-facing site live. We set up output caching and BLOB caching to cache pretty much all of the site. We also setup the Object cache. We figured we had our bases covered because we tried these things on our development site and they increased page load time significantly.

The site went live and it was doing well for most of the morning when 11 o'clock hit and we now had 3 time zones worth of people hitting the site. We suddenly noticed that the processor was getting pegged at 100% and that the amount of memory used was increasing quite quickly.

After spending a week looking at the performance monitor for various counters and checking Microsoft documentation, we had finally figured out that some of the memory leak was due to not cleaning up SPRequest objects. We cleaned up all of our custom code and this improved the site marginally. We also began tweaking the output cache to find a good balance and settled on 4 hours for pages to be cached. The BLOB cache works wonderfully, it caches images, and other Binary Large Objects. It is awesome to see whole pages load without images filtering in one at a time.

The site was still not running quite right and we had noticed on the object cache counter that objects were being thrown out of the cache as soon as they were put in. I began monitoring the SharePoint logs and found that pages were being invalidated and thrown out of the cache. So this led to a call to Microsoft. After the same questions and sending them an SPSReports CAB file, they came back saying that the object cache does not cache custom code objects. This didn't fare well as almost every page of our site has custom code on it. After looking over the options and Microsoft telling me that there was no expected date for a fix, we decided to monitor the site some more and noticed that the page output was still being cached, so the object caching not storing our code was only going to be a problem for the first person to hit that page. We decided that this was acceptable performance for the site.

In the next few blog posts I will explain the various types of caching and how they can help your MOSS site's performance and scalability (especially if an Internet-facing site).

Labels: , , , , , , ,

Thursday, October 11, 2007

Can I assist you?

Over the last few months I have been supporting the MOSS installation of an Internet facing site that I had been creating for a client over the last 6 months or so. With the support comes finding issues in code, performance, and other areas. One of these areas could be classified as interesting things about the SharePoint code itself.

I have been on the phone twice with Microsoft support for various issues and both times the tech has asked the same questions about the MOSS installation and any error messages that I had encountered. Then they usually ask me to install SPSReports from the CodePlex site, http://www.codeplex.com/spsreport. This tool gathers information from all of the system logs, the SharePoint logs, the registry, 12 hive, and various other areas. It compiles it into a CAB file that you can send to Microsoft so they can replicate your MOSS configuration on their end and figure out what the issue is.

If you plan on doing any customizations at all on MOSS or WSS then you may want to have this program installed on your development server, so when the time comes you are prepared to bundle up the file and send it to Microsoft.

The next few posts will be some of the many issues I have run across over the last couple months with MOSS.

Labels: , , , ,

Thursday, September 20, 2007

Chopped Column Names in Sharepoint

While working on a Sharepoint customization project, there were many areas where I needed to create custom site columns. Not thinking much about limits or restrictions I named the columns so that they were meaningful for me and others who may be supporting the site down the road. In a couple of pages I needed to run a query that would pull back information from the custom column (which I added to some custom lists). The custom column was named LFI CAD Possible Answers. When I tried to run the query by substituting in the _x0020_ for spaces, the query would not run.
Well one of my co-workers had written a utility for browsing the Sharepoint object model and getting back various things such as lists, GUIDs, column names, and most importantly the internal name for lists and columns. So although you name a custom column one thing, internally Sharepoint names it something else. For the most part this naming follows what you named the column except that spaces are replaced with _x0020_. Another limitation of the internal name is that it can only be 32 characters long. So if I take my custom column name and add the _x0020_ to the spaces we have: LFI_x0020_CAD_x0020_Possible_x0020_Answers. So take the first 32 characters of that name and you get: LFI_x0020_CAD_x0020_Possible_x00. This was the internal name for that column. The minute I adjusted my query to use that as the name of the field, the query ran fine.

Another side point to the column name and internal column name. We had created a custom column called E-mail. Well the internal name for this column becomes Email without the hyphen. The hyphen is just dropped completely from the column name. So be aware of these limitations when creating custom columns.

Labels: , , , , ,

Wednesday, May 2, 2007

Adding the bulk of Your Site Using Features

To add content to your Sharepoint site using features you need to create a feature.xml file or include the following elements into an existing elements.xml file.

To add content you make use of the Module element.


<Module Name="MainMasterPages"
Path="Masterpages"
Url="_catalogs/masterpage"
RootWebOnly="TRUE"></Module>

In the module element you give it a name attribute that will help you identify different modules. The Path attribute is the location of the files to upload in relation to the elements.xml file. The URL attribute is the URL on the Sharepoint site that you want the files to go. The RootWebOnly attribute is used to say if the file should only be available to the root web. Most of the time you can leave this true.

Within the Module element you place File elements that specify the actual files to upload to Sharepoint.


<File Url="main.master"
Type="GhostableInLibrary">
<Property Name="ContentType" Value="Landscape Master Page" />
<Property Name="Title" Value="Main Master Page" />
<Property Name="MasterPageDescription" Value="Master page for the home page." />
</File>

In the File element you specify the URL that you want the file to have in Sharepoint using the URL attribute. The Type attribute determines if the file will show up in the list or document library. If you set it to GhostableInLibrary then the file will show up. Inside the File elements you can place Property elements to provide additional information about the file. The property elements always consist of a name attribute that represents the name of the data and a value attribute that is the actual data.

In the example above we have a property called ContentType and it has a value that is the type of content that this file is, mainly a master page. The title property allows you to display the title that shows up in lists and when users can change the master page. The MasterPageDescription property allows you to provide a more detailed description of the file for users.

You can follow this same format to upload pretty much any type of content that you have. I have used it to upload master pages, style sheets, and images to the sites and folders that I wanted.

Following are some more links with more detailed information about uploading content:

http://www.andrewconnell.com/blog/archive/2006/12/20/5451.aspx

http://msdn2.microsoft.com/en-us/library/ms441170.aspx

Labels: , , ,

Friday, April 20, 2007

The Filling is the Best Part

In the previous post I showed how to create a list template. In this post we will create an instance of the list and populate it with actual data. This is the real power of a feature for lists. You create the basic Feature.xml and tell it where to look for the Elements.xml file.

In the Elements.xml file you create the following code:


<ListInstance
FeatureId="00BFEA71-DE22-43B2-A848-C05709900100"
Id="1999"
Description="Custom list for the LFI design groups."
TemplateType="100"
Title="LFI Design Groups"
Url="Lists/LFIDesignGroups">
<data>
<rows>
<row>
<field name="Title">35: Chill®</field>
</row>
<row>
<field name="Title">35: Mingle®</field>
</row>
</rows>
</data>
</listinstance>

In the listinstance node you place the feature ID GUID for the feature to base your list instance off of. In the sample code above this is the GUID for the feature of the basic list template. If you do not place a GUID in here, the documentation says that Sharepoint will substitute it with a default one. Don't ever do this as it can screw up the base list templates for the entire server. Always place a GUID in there yourself.

The documentation says that ID is optional but I always include it. It can be pretty much anything, an integer, a string, a GUID. As far as I can tell it is not used by Sharepoint. The only restriction is that it must be unique within the feature.

The description is what you want to show up for the list description. The template type is also grabbed from the list template that you are basing your list on. In this case the list template of 100 is for a custom list.

The title is the title you want to give the list.

The URL is what you want the URL of the list to be.

Inside the listinstance is a data node that contains a rows node and then a row node for each row in the list. Within a row node you place a field node and specify the name of the column that you are going to fill. In this case it is Title. You then place the data inside the node. In this case we are inserting two rows with data of 35: Chill and 35: Mingle. You can place as many nodes as you need to fill your list.

This feature works best if you need to fill a list with static data. You can easily recreate the list later or move the list to a new server such as staging or production.

For more information on list instances:

http://msdn2.microsoft.com/en-us/library/ms476062.aspx

And for more options for a field element:

http://msdn2.microsoft.com/en-us/library/ms437580.aspx

Labels: , , ,

Wednesday, April 18, 2007

A List Template of Your Very Own

To create your own list template using a feature is pretty easy. The only difficult part is trying to understand the documentation on the MSDN about which attributes are required and which are optional. When it comes to my experience with features and list templates, I have found that all of the attributes should be required, otherwise Sharepoint will place something in there for you and in our case this destroyed the out of the box templates on our Sharepoint site.

The first step is to create the Feature.xml file with a name for your feature and the location of the Elements.xml file.

<feature title="Simple List Feature" id="GUID" scope="Web" xmlns="http://schemas.microsoft.com/sharepoint/">
<elementmanifests>
<elementmanifest location="Elements.xml">
</elementmanifests>
</feature>

After that you can create the Elements.xml file and place the ListTemplate node in there.

<elements>
<listtemplate name="SimpleList" displayname="Simple List" type="20" description="This is my simple list." basetype="0" onquicklaunch="FALSE" securitybits="11">
</elements>

The ListTemplate tag is pretty simple. You give it a name and a display name. The display name shows up in the site settings area for list templates. The description field is used to provide more information about your list template. The basetype is the default schema for the lists created from this template. Most times this will be 0. The onquicklaunch allows the list template to show up on the quick launch bar. The security bits allows for read, write, and schema design security.

There are many other fields that you can use in the list template to customize it the way you want. The resource below lists all of these fields.

<edit>
It has been brought to my attention that I forgot to mention the schema.xml file. At the time that this post was originally written, we copied a schema.xml file from an existing list and then modified it. Microsoft recommends this approach as building the schema file from hand is time consuming and very prone to errors. There are also tools out there that will generate schema files from a list that you build using the UI.
</edit>

http://msdn2.microsoft.com/en-us/library/ms462947.aspx

Labels: , , , ,

Friday, April 6, 2007

Back to the Features - Element.xml

In this installment of features we will look at the Element.xml file (or whatever you called it). This is the file that does the actual work in a feature. An example file might look like this:


<?xml version="1.0" encoding="utf-8" ?>
<elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="ViewPhotoPage"
Path="Pages"
Url="Pages"
RootWebOnly="FALSE">
<File Url="viewphoto.aspx"
Type="GhostableInLibrary">
<property name="Title" value="View Photo">
<property name="Description" value="The view photo page.">
</file>
</module>
<Module Name="Images"
Url="PublishingImages"
Path="images"
RootWebOnly="TRUE">
<file url="LFILogo_NoByline.gif" type="GhostableInLibrary">
</module>
</elements></p>

The elements element is required to be in the page. Inside this node you place the module nodes. Each module node does one type of similar action. Modules are used for placing files in the appropriate folders. In this feature we have a module called "ViewPhoto". This module places an aspx file in a directory on the Sharepoint site. The path is the location of the file or files in relation to the Elements.xml file. In this case the files are located in a folder called Pages. The URL attribute tells the feature where in the Sharepoint structure to put the files in this module. In this case it is the top level Pages list. The RootWebOnly attribute says if the files can only be accessed in the root web for the site.

Within the module node you place file nodes that specify the actual file. The URL attribute is the URL you want in the Sharepoint structure for this file. Typ determines if the file shows up in the page libraries. If you use GhostableInLibrary, the page will show up when you browse to the pages library.

Within the file node you can place property nodes that give additional attibutes for the file. In this case we have a title property and a description property. This allows for more descriptive information about the files.

Some things to look out for are the naming conventions in Sharepoint 2007. In some areas a library will be called PublishingImages but can be referenced using just Images. When creating features if you get some of the parts wrong, you can mess up the file system and the default templates for a Sharepoint site. Trust me on this one, I will explain some of the mistakes we have made and the issues we have found in later posts.

For now here are some more reference sites that explain more of the options for the Elements.xml file:

http://msdn2.microsoft.com/en-us/library/ms453137.aspx

http://msdn2.microsoft.com/en-us/library/ms434127.aspx

In the next few posts I will demonstrate how to do various activities using features.

Labels: , ,

Thursday, March 22, 2007

Beware the UI Feature List

I know that I promised to post about features, but I came across an interesting bug in the MOSS feature user interface that needs to be discussed. I will continue on with the feature posts. Today I was recreating our site using the features I have been working on for the last 2 weeks. In the Sharepoint feature UI you get a list of the installed features in either a site collection or a site with buttons next to them to activate or deactivate the feature. Well I was activating the features when I received a message asking me if I wanted to really deactivate this feature. This did not make sense since the feature was not activated yet. I clicked cancel and went back to the UI for the features. I had clicked on the right feature to activate so I refreshed the page and tried it again. This time the feature activated just fine, so I really didn't think nothing of it.

About 10 minutes later I was doing the same process when I received an error that the content type did not exist. This was odd because the feature I was trying to activate did not do anything with a content type. As a side note right here I need to say that I am not the only one working on this install of Sharepoint. There are three of us working on two separate projects and sharing one 12 hive. This was only a problem once before, but that is another story for later. So I poked into the log files and found that there were some errors for JT features so I mentioned to my colleague Joel that he had some errors in the log. He looked into it and found that the error was his feature but that it was being activated on my site. So I looked into the libraries and lists for my site and sure enough there was his list created on my site.

After more poking around we guessed that the UI for the features list is indexed to an internal list of the installed features. What was happening was I would load the page with the list of features and then Joel would install a new feature that was higher up alphabetically in the list and would push the internal list down one. So on the list I was viewing I would go to activate item 3 and in the internal list it would really be item 4. After we suggested this theory to another colleague, he created a simple test by creating three features that began with z and would create an image that corresponded to the feature id. He then loaded the UI page and installed a feature that began with an a. Sure enough if he went to activate the middle z feature it actually activated the first z feature. So we concluded that you need to (if you have multiple people working on the same 12 hive) always refresh the UI page right before activating a feature to make sure you are activating the right feature or use the command line stsadm command to install and activate the features.

Needless to say this provided some entertainment for us this morning.

Labels: , , ,

Thursday, March 15, 2007

Let's start at the beginning.....

To create a feature you first need to define the Feature.xml file. Here is a sample file:


<?xml version="1.0" encoding="utf-8" ?>
<Feature xmlns="http://schemas.microsoft.com/sharepoint/"
Id="1C552111-5D53-440d-8E6E-50E3B5EB5492"
Title="LFI View Photo Page"
Description="Creates the view photo page."
Scope="Web"
Hidden="false">
<elementmanifests>
<elementmanifest location="Elements.xml">
</elementmanifests>
</feature>

The main areas of this file are the feature node. Here you need to give the feature a unique ID (GUID). You can accomplish this by opening Visual Studio 2005 and clicking on tools. Then select create GUID. While working with feature files, I have noticed that some attributes require the curly braces around the GUID and some don't. You may have to follow the feature documentation to figure this out. The MSDN has good definitions of the elements and the attributes for the elements.

http://msdn2.microsoft.com/en-us/library/ms439657.aspx

The other attributes of the feature element are mostly for your own benefit. The title and description will show up in either the site features or site collection features list. The scope determines where the feature will be installed. For most situations this will be "Web" if you want to deploy the feature to the entire site collection or "Site" if you want it available to the subsites. The hidden attribute determines if the feature will show up in the feature list. If you want to be able to see the feature to activate it, you need to set this to false.

The ElemenetManifests element contains an ElementManifest element that has one attribute, Location. This attribute tells the feature where to look for the rest of the information to activate the feature. In the next post I will begin looking at the Elements.xml file. You can name this file whatever you want, but I find having a convention like naming them all Elements.xml keeps things neat.

Labels: , ,

Thursday, March 8, 2007

Is Your CSS !important?

Today while working on the LFI project, I was creating a page layout for the pages that display a link to the CSI specifications for the products. I added a summary links web part to the page and it accomplished the task that I wanted. The problem was the default color scheme and design that the web part employed. It would never match the color scheme of the current LFI site.

I began where any other Web desgner would and created a CSS class in my external style sheet to change the color to the more appealing green. I added two classes:

a.CSILink {
color: #457E54;
text-decoration:none;
font-size:9pt;
font-family: Arial;
}
a.CSILink:hover {
color: #497c21;
text-decoration:none;
font-size:9pt;
font-family:Arial;
}

I tested the classes and found that the anchor was not changing color. When I rolled over the anchor the appropriate class was being used.

Now knowing the MOSS has thousands of CSS classes and XSL sheets for design, I began to poke into the XSL style sheet for the web part and modified the sheet by copying one of the templates and creating my own. We had done this before for antother part of the site and it worked nicely. Not so much this time.

The style was not being applied no matter how I modified the CSS and XSL sheets. I called over my fellow employees and they looked over the CSS and aspx pages and could not find anything wrong. We tried a few other methods when Art suggested we add the word !important after the color for the anchor tag. I had never heard of this keyword before and did not know what it did, so I placed it into the CSS sheet and tested the style.

This time it worked! There was a small glitch that the hover style did not work now, so I had to go back into the style sheet and add !important to the hover style as well.

Art explained that the !important keyword says that this style should be applied over all others. The only explanation for why it wasn't working before is that somewhere in the Sharepoint CSS classes there is one that specifies an anchor tag in the same combination that I have but that none of the links in Sharepoint have a hover feature, so the hover class worked fine.

Labels: , , ,