Error When Trying to Delete a Master Page: “Server error: This item cannot be deleted because it is still referenced by other pages.”

I’ve had this happen often and I’ve usually just left the unused master pages, since they aren’t really hurting anything.  Today I finally decided to try to see if I could get rid of a pile of old copies of master pages I had lying around, and I found this Microsoft article which explains a workaround.  Turns out it’s a “known issue”.  Once you’ve gone through these steps, you ought to be able to delete the master page.  However, I’ve found that this workaround doesn’t always work in Site Collections with variations enabled.

When you try to delete a master page file from the Master Page and Page Layout Gallery on the Site Settings page in Microsoft Office SharePoint Server 2007, you receive the following error message:

This item cannot be deleted because it is still referenced by other pages.

This error message occurs even when the master page file is not associated with a SharePoint Server 2007 site.To work around this problem, mark the master file as hidden so that the master file does not appear as a selection when you create a new site. To do this, follow these steps:

  1. Use an account that has administrative permissions to log on to the Web application that is hosted on the SharePoint Server 2007 server.
  2. Click Site Actions, click Site Settings, and then click Modify All Site Settings.
  3. Under Galleries, click Master Page and Page Layout Gallery.
  4. Click the list next to the master file that you want to hide, and then click Edit Properties.
  5. On the list next to Content Type, click Page Layout.
  6. Click to select the check box next to Hidden Page, and then click OK.
  7. Click the list next to the master file, and then click Check In.
  8. On the Check In page, select the options that you want, and then click OK.
  9. Click the list next to the master file, and then click Publish a Major Version.
  10. On the Publish a Major Version page, enter a comment, and then click OK.
  11. Click the list next to the master file, and then click Approve/reject.
  12. Next to Approval Status, click Approved, and then click OK to approve the changes.

Displaying the Render Date and/or Time in SharePoint Pages

This is a simple enough task with a little JavaScript.  Inserting the script below into your master page will output the date and time in the simplest way possible when the page is rendered:

   var dt = new Date();
  document.write(dt);

If your language is American English, you will see the following: Fri Oct 24 18:19:06 EDT 2008.  Of course, if you’d like things formatted a little more nicely, you can always expand the JavaScript.

Another nice trick is to use similar JavaScript to display the year information for the copyright notice that you are likely to have in your footer or elsewhere on your page.  The copyrightYear function below will return startYear if it is that year or earlier, and startYear-currentYear (e.g., 2007-2008) if the currentYear is greater than startYear.

// copyrightYear: Display a copyright year range.
// Arguments:
//		fieldName:	startYear
//
<!-- This Javascript function is used to display the copyright year range.
function copyrightYear(startYear) {
 // Get the current date
 var dt = new Date();
 var y  = dt.getYear();
 var yEndYear = "";
 // Y2K compliant
 if (y < 1000) y +=1900;
 // If the current year is greater the startYear, then display the range, otherwise just the current year
 if (y > startYear) yEndYear = "-" + y;
 document.write(startYear + yEndYear);
}

If you called the function like so today:

   copyrightYear("2007");

you would see 2007-2008.

You can see a working example of this on our demo page.

How to Fix Recurring Meeting Workspace Error: ‘g_InstanceID’ is undefined

I was having a problem with Meeting Workspaces today.  The links to each meeting instance on the left Quick Launch were not working, and every time we clicked on one of them, we would get a JavaScript error: ‘g_InstanceID’ is undefined. 

At first, I assumed that my CSS must be hiding a control that was required for the navigation links to work.  Then I found a post by Mike Monjeau entitled MOSS – How to fix recurring Meeting Workspace error: ‘g_InstanceID’ is undefined that describes the fix for this.

Basically, when you use a master page other than default.master for a Meeting Workspace site, you can get this error.  If you add the following lines into your new master page, you can solve the problem:

  1. Add the following line of code under the <%@ Import Namespace=”Microsoft.SharePoint” %> tag:
    <%@ Register Tagprefix="Meetings" Namespace="Microsoft.SharePoint.Meetings" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
  2. Add the following line of code after the opening <body> tag:
    <Meetings:PropertyBag runat="server"/>

     

     

     

Branding for _layout Pages in SharePoint

I got a comment on one of my earlier posts about SharePoint branding (the look and feel of sites, including colors, fonts, page layouts, etc.).  I couldn’t respond directly due to the person’s communication settings on their Live Space, so I thought I’d answer it here:

Marc,
Great blog, but I was wondering if you could fill in some gaps for me.  I move elements around in my custom master page and I want those changes applied to the application pages as well.  I have been trying to find out how to do that.  I didn’t rename or remove any pieces.  I only rearranged them or made them not visible on the page.  So how can I make those changes appear on the /_layouts pages?  Thanks for any help you can provide.

Pages in the _layouts directory are actually stored in the hive on the server’s hard disk rather than in the database.  Each page is available to all sites.  These pages also have a different master page (also stored in the hive) called application.master.  Therefore, when you make changes to default.master (Don’t change it directly — make a copy — you never know when you might need to go back!), those changes aren’t applied to the _layouts pages.

What you should do is to turn your CSS into a theme and apply that to your site.  This works because the theme is applied to all of the pages, including the _layouts pages.  Keep in mind that there are some CSS classes in application.master that don’t occur in default.master as well as some different constructs, so you may need to go back and forth a bit.

SharePoint 2007 (MOSS) Branding CSS Tricks

Having done branding (meaning applying custom CSS to change colors, fonts, etc.) to quite a few MOSS Site Collections, I wanted to offer a few tips and tricks to keep things clean and easy to maintain.  I’ve mentioned some of these tips before, but I wanted to get them all into one post so that they could be more useful.

  • Never edit default.master; take a copy and name it something logical, like myportal.master.  You might need default.master again, and once you customize it, you are out of luck.
  • Edit your myportal.master as you need to in SharePoint Designer.  I usually limit these edits to images that I want on every site in the Site Collection and changes to Web Part Zones that should apply across the board.
  • Attach a custom CSS file to your master page.  I store this custom CSS in the Style Library folder and I name it the same as my master page, e.g, myportal.css.  Storing it in the Style Library folder means that it will be backed up with the rest of the Site Collection.  (You have set up daily backups of your Site Collection, right?!?!?)
  • Definitely, definitely, definitely install the Internet Explorer Developer Toolbar.  This invaluable tool does many things, but most importantly for this exercise, you can use the Find / Select Element By Click option to figure out what CSS classes you want to override.
  • Only add classes and elements into the custom CSS that you are using to override the default.  If you copy and paste from core.css (the default CSS file) using Designer, you will get the entire class’s definition.  This will make your custom CSS much bigger than it should be and more confusing to maintain.  Here’s an example…If you copy from core.css, you might have:

    .ms-globalbreadcrumb {
        font-size: 8pt;
        text-align: right;
        background-color: #FFFFFF;
        padding: 2px 10px 2px 5px;
    }

    If you only want to change the background color, then you should have:

    .ms-globalbreadcrumb {
        background-color: #FFFFFF;
    }

    since this is the only thing that you are overriding.

  • Be sure that you only include each class once in your custom CSS.  If classes exist more than once it will cause you problems because you will probably change the first one and then the second one will override your override!
  • Try to keep the CSS classes in an order that generally goes from the top left of the page to the bottom right, just like the way you read a page.  It makes finding things easier and is worth the little bit of extra effort it takes.
  • Comments are good!
  • Don’t forget to check in a major version of your master page and approve it, and check in your custom CSS (no need to approve here).  If you don’t, you will see all of your changes, but everyone else will be asking you why you haven’t changed anything!

 

Technorati tags: , , , ,