Printer-Friendly CSS and Print Preview in MOSS 2007

This post was driven by a request I recently received to add a Print Preview button on a SharePoint page.  When clicked, the Print Preview button will popup a window without any SharePoint navigational elements.  

I decided to create a separate CSS file (called PrintPreview.css) to overwrite the following MOSS CSS classes:

/* Hide MOSS Globa Links, title, banner and Top Nav area */
.ms-globalTitleArea {display:none;}
.ms-globalbreadcrumb {display:none;}
.ms-bannerContainer {display:none;}

/* Hide MOSS Page Title area */
.ms-TitleAreaFrame {display:none;}
.ms-titlearealeft {display:none;}
.ms-titlearea {display:none;}
.ms-pagetitle {display:none;}

/* Hide MOSS Bottom area */
.ms-pagebottommarginleft {display:none;}
.ms-pagebottommargin {display:none;}
.ms-bodyareapagemargin {display:none;}
.ms-pagebottommarginright {display:none;}

/* Hide MOSS quick launch area */
.ms-navframe {display:none;}
.ms-pagemargin {display:none;} 

/* Hide MOSS Editor tool bar menu to prevent user from editing a comment*/
.ms-rtetoolbarmenu {display:none;}

/* Remove border from MOSS body area */
.ms-bodyareaframe {border:none 0px;}

Since the Print Preview button was going to be added to an existing User Control (wrapped in a Web Part), I then added the following JavaScript code to the markup page of each user control.  Doing so will also allow you to hide specific elements you might not want to be displayed in the print preview window:

<script type=”text/javascript”>

    //Function to print Web Part
    function PrintPreview() {
        var sUrl = window.location.href + ‘&PrintPreview=true’;

        if (window.location.href.indexOf(’?') == -1) {
            sUrl = window.location.href + ‘?PrintPreview=true’;
        }

        window.open(sUrl, “_blank”, “width=800,height=600,resizable=1,toolbar=1,status=1,titlebar=1,menubar=1″, true);
    }

    if (window.location.href.indexOf(”PrintPreview=true”) > -1) {
         //This is where you can hide custom elements by ID or name
         //For example here is the code to hide a command button with an ID of “button1″
        document.getElementById(’button1′).style.display = ‘none’;

        //Load PrintPreview CSS
        SetPrinterFriendlyCSS();
    }

    function SetPrinterFriendlyCSS() {
        document.write(’<link type=”text/css” href=”/_layouts/Customer/Application/PrintPreview.css” rel=”stylesheet” />’);
    }

</script>

To hide specific custom elements on your page, you could also add a “noprint” class attribute to each element you do not want to be rendered in the print preview mode.  The not print class will be added to the PrintPreview.css file:

/* Add NoPrint class to the original markup */
.noprint {display:none;}


The last technique will be to overwrite the class attribute used by the element you are trying to hide:

/* Hide right column to hide custom action buttons in CustomXXX.ascx*/
.col_actions {display:none;}


About the Author

Gilles Uréna is an independent SharePoint Consultant. Gilles is the owner of SharePoint Global Services, an organization built from the ground up to provide consulting services on the SharePoint platform and surrounding technologies. You can contact Gilles at gilles.urena@sharepointglobalservices.com

Wrapping a User Control in a Web Part

This article demonstrates how to wrap a custom User Control in a Web Part and deploy it as a feature using WSPBuilder (http://www.codeplex.com/wspbuilder).

This article assumes you have some basic knowledge about WSPBuilder and how to deploy SharePoint assemblies as solution packages (wsp).

Solution Overview

The solution architecture consists of the following two projects:

  • A WSPBuilder Project using the Visual Studio project template installed during the setup of WSPBuilder.  This project will allow us to create the wsp file to be loaded in the SharePoint solutions store.
  • A classic ASP.Net Web Application Project to create our user control.  We will create custom post-build scripts to copy the user control to the CONTROLTEMPLATES sub-folder created in the WSPBuilder project.

Please download the white paper here.

About the Author

Gilles Uréna is an independent SharePoint Consultant.  Gilles is the owner of SharePoint Global Services, an organization built from the ground up to provide consulting services on the SharePoint platform and surrounding technologies.  You can contact Gilles at gilles.urena@sharepointglobalservices.com

Administrator and Developer Guide to Code Access Security in SharePoint Server 2007

Another great article from Critical Path Training (Andrew Connell): Administrator and Developer Guide to Code Access Security in SharePoint Server 2007  (http://msdn.microsoft.com/en-us/library/ee909485.aspx)

Summary: Understand Microsoft .NET Framework code access security (CAS) and how to work with it in custom SharePoint solutions. Explore configuration options, get best practices for managing CAS in SharePoint environments, and walk through a complex CAS scenario.

Contents :

  • Introduction to Code Access Security and SharePoint
  • What Is Identity Security?
  • What Is Code Access Security?
  • Link Demands and Allowing Partially Trusted Callers
  • Understanding the Components of CAS in ASP.NET
  • Why CAS Is Important to SharePoint Administrators
  • Why CAS Is Important to SharePoint Developers
  • Working with CAS in SharePoint
  • Best Practices for Managing CAS in SharePoint
  • Real-World SharePoint and CAS Walkthrough
  • Conclusion

Richmond SharePoint Saturday

Hi,

I just came back from presenting at the SharePoint Saturday event in Richmond, Va.  My session was about how to use Enterprise Content Types and Metadata with MOSS 2007. 

You can download the presentation in PDF or PPT format here.