Skip to main content

Sitecore

Sitecore Configuration Patch to Open a PDF in Same Browser Window

If you search for how to open a PDF file in the same browser window in Sitecore, you will certainly find plenty of help. The issue is a configuration setting that by default forces the download of all media types. Simply change the value of this configuration and you are set. When I first ran into this a few years ago, the trouble I had was how to write a patch file to handle this as all the examples just pointed to the setting you needed to change.
Sitecore provides more than a few configuration files, and as these files are subject to change with each update from Sitecore you should never modify the files directly. For some files like the Web.config or Layers.config, you will need to transform the original through a mechanism of your choosing (TODO: INSERT LINK TO FUTURE BLOG POST HERE). For configurations that contain the <sitecore> node, the proper way to make changes is by deploying configuration patch files. Sitecore Configuration patch file examples for 8.2 unfortunately do not include the exact scenario of replacing the value inside an element like the “false” in <forceDownload>false</forceDownload>. If you match the configuration structure exactly without any attributes (as I did here in this gist), your configuration takes precedence and doesn’t cause any errors. The gist I created also has a few other tweaks to help IE load large files and keep the original file extension in the URL.
The 9.0 documentation does mention the “patch:instead” attribute, which as best I can tell has been around since 6.0 but was mysteriously absent from older documentation and any examples I could find 2 years ago. Use it with caution, though, as it appears Sitecore has a bug if you are matching the XML you are replacing in your patch file.
 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Matt Connolly

More from this Author

Categories
Follow Us