ARTICLES

Home  > Articles  >  Robust print view for SharePoint list views
 Nearly any intranet or extranet and especially Internet site will require to have a print view for pages or sections of the site. If you take a standard approach of modifying CSS you might be spending days trying to get details of list views acceptable for printing. Here we take a look at a solution that will potentially save you lots of time.

First we`re going to create a simple ASPX page and drop it in _layouts folder of your site either by using a feature or manually if you want to test things out. Your page will perform simple .NET and SharePoint manipulations so make sure you have all of the references and assemblies registered either in a page or in your library depending if it`s a test or production solution.

In your code behind Page_Load method insert the following:

SPList list = SPContext.Current.Web.Lists[`MyList`];

SPView view = list.DefaultView;

Response.Write(view.RenderAsHtml());

 

Above, we get a hold of the list, so if you have any specific list - there is your chance to get a handle to it. Then, we take advantage of the RenderAsHtml method available on a SPView. In this case, we`re working with the default view - which will return all items unless other default view has been specified. This means that even if users create custom views, as long as you get a hold of their reference properly, your list will be rendered in a print view no matter how complex calculations or filters are in your view.

This approach will surely save you time on generating print views for list views and not reduce or break existing functionality.

Hope you found this useful,

 
Yaroslav Pentsarskyy, Microsoft MVP
Blog: www.sharemuch.com