Printing Posts: newbie

Dec 8, 2008 at 8:02 PM
Edited Dec 8, 2008 at 8:19 PM

Finally got BlogEngine.Net installed and am trying to customize it. Being a newbie at blogs, I'm not sure if the following can be done: can a printing link be created for posts, comments, a blog page that (1) creates a printer friendly view, (2) has a link that when clicked displays the printer dialog?

Unfortunately, I'm not very skilled at scripting, server-side issues, but am eager to learn. I would appreciate any suggestions, help.


Kind Regards,


Dec 8, 2008 at 9:55 PM
Have a look at my post titled Printer Friendly Posts for something that might work for you...

Dec 8, 2008 at 10:15 PM
Hi Chris,

Yes, this (having "print" and even "copy to clipboard") would be fantastic, but, at my limited skill level (am retired social worker), I can't guess how to add it to my brand new blog (

I have an HTML editor, plus can FTP upload, if I knew which files to add script to, what script to add, where in the file to add the script, how and where to use those 2 files in the "printer friendly" zip folder I downloaded.

Would it be possible to walk me through?

Thank you for your help.

Kind Regards,


Dec 8, 2008 at 11:40 PM
Sure, no problem. 

  1. Copy the PrinterFriendly.aspx and PrinterFriendly.aspx.cs into your root folder ( referred to as ~/ )
  2. Open your themes folder ( ex. ~/themes/Standard ) and then edit the file PostView.ascx ( ex. ~/themes/Standard/PostView.ascx )
  3. Add the following syntax wherever you want the printer friendly link to be displayed:  <a href="~/PrinterFriendly.aspx?id=<%=Post.PermaLink %>">Print</a>
What's happening in the background?  The anchor link calls referrs to PrinterFriendly.aspx and passes the PermaLink value (the GUID) of the post.  The PrinterFriendly.aspx page reads the ID attribute and lookups up the post.  If it finds the post then it displays the contents as it's layed out in the PrinterFriently.aspx page, otherwise you get directed to the error404.aspx page.  You can customize the PrinterFriendly.aspx page as you would like. 

That should do it for you.  Let me know if you have any problems.

Dec 8, 2008 at 11:55 PM
Edited Dec 8, 2008 at 11:57 PM

Hi Chris,

Thanks for your reply and help.

Let me see if I understand:

Re: step 1 ("Copy the PrinterFriendly.aspx and PrinterFriendly.aspx.cs into your root folder ( referred to as ~/ ) "

     The blog is not in the site's root folder but instead in a folder called "/blogs" so would I copy the 2 files into the root or into the /blogs folder?

Re: step 2 ("Open your themes folder ( ex. ~/themes/Standard ) and then edit the file PostView.ascx ( ex. ~/themes/Standard/PostView.ascx ) "

    For editing the file "PostView.ascx" is this the file in which I would place "<a href="~/PrinterFriendly.aspx?id=<%=Post.PermaLink %>">Print</a> " ?
     I am guessing here that depending where in the page I insert the script, the print hyperlinked text will hopefully display in the post. Is this correct?
     Could I also add the print feature to a comment?

or do I need to insert the script in a different file (s)?

Again, thanks for your help.

Let me know, and then I will give it a try.

Kind Regards,


Dec 9, 2008 at 12:19 AM
Yes, your root would be /blogs, so place the PrinterFriendly files into that folder.

Yes, insert the anchor into the PostView.ascx file where you want the text to be displayed.  You could also replace the text with an image of a printer, or whatever you want.

The comments for a post are already included in the PrinterFriendly view.
Dec 9, 2008 at 12:46 AM
Edited Dec 9, 2008 at 12:56 AM
Hi Chris,

Not very good at this. I've load the 2 files to the /blogs folder, but I keep getting an error message that the resource cannot be found.

The problem may be getting the correct pathname to the 2 files. Currently, the path for PrinterFriendly.aspx is probably: So, if the scripts are seeking: "<a href="~/PrinterFriendly.aspx
the ~/ before PrinterFriendly.aspx is missing.

Not sure how to fix this. I've tried a variety of combinations altering the script: "<a href="~/PrinterFriendly.aspx?id=<%=Post.PermaLink %>">Print</a> (for example, removing ~/) with no success, just error messages.

Like this (with the 2 files in the /blogs directory). (I also tried removing ~/ from the script, but this produced another error message.) 

Server Error in '/blogs' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /blogs/~/PrinterFriendly.aspx




Version Information: Microsoft .NET Framework Version:2.0.50727.1433; ASP.NET Version:2.0.50727.1433

<!-- [HttpException]: The file '/blogs/~/PrinterFriendly.aspx' does not exist. at System.Web.UI.Util.CheckVirtualFileExists(VirtualPath virtualPath) at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile) at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean noAssert) at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp, Boolean noAssert) at System.Web.UI.PageHandlerFactory.GetHandlerHelper(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) at System.Web.UI.PageHandlerFactory.System.Web.IHttpHandlerFactory2.GetHandler(HttpContext context, String requestType, VirtualPath virtualPath, String physicalPath) at System.Web.HttpApplication.MapHttpHandler(HttpContext context, String requestType, VirtualPath path, String pathTranslated, Boolean useAppConfig) at System.Web.HttpApplication.MapHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) --><!-- This error page might contain sensitive information because ASP.NET is configured to show verbose error messages using <customErrors mode="Off"/>. Consider using <customErrors mode="On"/> or <customErrors mode="RemoteOnly"/> in production environments.-->

Any suggestions about getting how I can get the locations and pathnames correct?

Kind Regards,


Dec 9, 2008 at 1:24 AM
No worries... Insert this syntax...

<a rel="nofollow" target="_blank" href="<%=Utils.RelativeWebRoot %>PrinterFriendly.aspx?id=<%=Post.Id %>">Print</a>
Dec 9, 2008 at 1:26 AM
I just tried your site and it's setup correctly...  Have a look at your last post in PrinterFriendly mode!
Dec 9, 2008 at 1:45 AM
Forgot to mention you need to either add <%@ Import Namespace="BlogEngine.Core" %> to the top of your PostView.ascx file or change the previous syntax to look like:

<a rel="nofollow" target="_blank" href="<%=BlogEngine.Core.Utils.RelativeWebRoot %>PrinterFriendly.aspx?id=<%=Post.Id %>">Print</a>

Sorry about that...


Dec 9, 2008 at 2:06 AM
Edited Dec 9, 2008 at 3:31 AM
Hi Chris,

Some progress, but still some things that need fixing.

So far, using the latest script, <a rel="nofollow" target="_blank" href="<%=BlogEngine.Core.Utils.RelativeWebRoot %>PrinterFriendly.aspx?id=<%=Post.Id %>">Print</a>
the print link is showing in the posts, and now I get a print view but with errors on the page.

Also, I am not getting a printer dialog to display (like on your blog site), which allows the printing.

Is there an additional piece of script that I need to add to get the printer dialog to display, or is that the page script error in the screenshot?

Again, thanks for your help.

Kind Regards,

Dec 9, 2008 at 2:25 AM
At the bottom of the PrinterFriendly.aspx page is some JavaScript information that loads the SyntaxHighlighter components.  If you are not planning on posting code to your page you can remove the offending scripts.  Just edit the PrinterFriendly.aspx and head to the bottom of the page.  There you should see a bunch of <script> tags and a <link> tag:

<script type="text/javascript" src="/js.axd?path=/dp.SyntaxHighlighter/Scripts/shCore.js"></script>
<script type="text/javascript" src="/js.axd?path=/dp.SyntaxHighlighter/Scripts/shBrushCSharp.js"></script>
<script type="text/javascript" src="/js.axd?path=/dp.SyntaxHighlighter/Scripts/shBrushXml.js"></script>
<script type="text/javascript" src="/js.axd?path=/dp.SyntaxHighlighter/Scripts/shBrushCss.js"></script>
<script type="text/javascript" src="/js.axd?path=/dp.SyntaxHighlighter/Scripts/shBrushJScript.js"></script>
<script type="text/javascript" src="/js.axd?path=/dp.SyntaxHighlighter/Scripts/shBrushVb.js"></script>
<link type="text/css" rel="stylesheet" href="/css.axd?name=/dp.SyntaxHighlighter/Styles/SyntaxHighlighter.css" />
<script type="text/javascript">
    window.onload = function () {
        dp.SyntaxHighlighter.ClipboardSwf = '/dp.SyntaxHighlighter/Scripts/clipboard.swf';

Remove them and it should solve the script errors.  This brings up an interesting point.  Since this page isn't being rendered with the site.master page you aren't inheriting any extensions that would normally be firing with a post and/or page view.  So if you are using tracking code like Google Analytics then you will need to manually add them to this page.
Dec 9, 2008 at 2:30 AM
Hi Chris,

Thanks, that script deletion removed the error.

How do I get a print dialog box to pop-up so that the displayed printer-friendly post can actually be printed?

Kind Regards,
Dec 9, 2008 at 2:37 AM
Edit the PrinterFriendly.aspx file and change the <body> tag to:
<body onload="javascript:print()">
which will pop up the print dialog after the page loads.  Or you could add an anchor tag like the following:
<a href="javascript:print()">Print</a>
which will do the same when someone clicks it...
Dec 9, 2008 at 3:26 AM
Hi Chris,

Thanks, all is working well. (For now, went with using both ways to summon printing dialog.)


Plus, this discussion topic has a wonderful set of instructions that can be referenced to set up printing.

Again, thanks much!

Kind Regards,