Ambiguous error message “An error has occurred on the server” working with a Wiki definition

I have spent the morning trying to resolve what was causing an ambiguous error message that was occurring on a custom built SharePoint site. Whilst attempting to deploy a custom site definition that includes a Wiki Homepage feature and a series of predefined wiki pages in the Site Pages library the error message “An error has occurred on the server” can be seen displayed in the Recently Modified section on the left when viewing the various wiki pages in the Site Pages library.

Error message "An error has occurred ont he server." from Wiki Site Pages library

The context in this case is a Feature containing a custom site definition. As part of the custom site definition I am configuring an instance of the Site Pages library and enabling the Wiki Home Page feature. The Site Pages library is provisioned with a custom Home page plus as set of additional custom wiki pages associated with the puprose of this new site type. The solution and features deploy and the custom site provisions correctly except for this one error frustrating.

After some digging around I discovered that this is related to the Modified field on the Site Pages library and specifically with the fact that this part of the wiki page library expects this field to be indexed within SharePoint. I’ve checked list definition/schema in my feature and the field is defined with the Indexed attribute set correctly i.e.

<FieldID={28cf69c5-fa48-462a-b5cd-27b6f9d2bd5f}” StaticName=ModifiedIndexed=TRUE />

but it seems to make no difference to the setting of the deployed and instantiated library!

If I browse to the list settings for the Site Pages library and manually set the field Modified to be indexed then the error goes away and the Recently Modified section displays the correct list of pages. This doesn’t help me solve the problem as I need the feature to be working when a site is created and not require any manual intervention such as this. It did at least put me on the right track.

After trying a number of tweaks to the XML config of the site definition with no success I decided that fixing the issue after the site is created was going to be the simplest approach. To acheive this I implemented a feature receiver that, post feature activation, ensures that there is an index created on the Modified field in the new site’s Site Pages library.

        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            SPWeb site; 
            try
            {
                site = SPContext.Current.Web;
                if (site != null)
                {
                    SPList objList = site.Lists["Site Pages"];
                    SPField objModified = objList.Fields["Modified"];
                    objModified.Indexed = true;
                    objModified.Update();
                    objList.FieldIndexes.Add(objModified);
                    objList.Update();
                    site.Update();                 
                }
            }
            catch (Exception ex)
            {
                // do something with the exception
                string message = ex.Message;
            }
        }

With this feature receiver in place the Modified field is now correctly index and the Recently Modified section of the Site Pages libary page works correctly.

Advertisements

6 Comments

Filed under General SharePoint Development, SharePoint 2010

6 responses to “Ambiguous error message “An error has occurred on the server” working with a Wiki definition

  1. Flo

    great! solved my problem! Thanks for sharing! 🙂

  2. rasor

    Thanks, Kirk 🙂
    The index on column modified fixed the errors:
    – “Query needs to have a WHERE clause with an NVP field if UseNvpForOrderBy is TRUE” and
    – “No XsltListViewWebPart was found on this page”

  3. Julia

    Hi Kirk; what does one do when there’s no “modified” field in the list? I have “modified by” but no “modified”….

    • It is a standard column so you need to think about why it would not be there. Is it just not visible on your view or has someone else removed or set the column to hidden maybe? I would check the content type and verify that it is there or not. If it’s not you could try adding it from the existing site columns.
      Hope this helps.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s