Sitecore: How to Enable Media Library Item Preview

August 10, 2012

Nerd

As a medical company who has to get version numbers from MLR (Medical Legal Review), managing pdf versions and going through workflow approval process for these files just like other site content is very important to one of our SiteCore clients.

They were not happy that their Medical/Legal Sitecore reviewers/approvers would get the “no layout” message when trying to Preview (pdf) files to approve them from Workbox.

image

image

Upon inquiry, I received this response from Sitecore:

“Only thing I can think of would be to create a custom workflow command and action that will allow for preview of the PDFs. Don’t know of an out of the box way to do this.

They could create a layout that’s just designed for PDF preview and the custom command would open a new window whose sole purpose is to allow for the PDF preview.”

I then asked what the expected media item workflow was, and was told the client is supposed to (know to ignore the Preview button and to) click on “Open” then go to the Media tab & click “Download.”

Here’s how I got the preview button to work. If you know of a better (or built-in) way, please let me know in the comments. Thanks!

  1. Create a new MAIN layout (not sublayout) item (called “Data Item Preview”)
    image
  2. In your code base, recreate that newly-created “Data Item Preview.aspx” page so it has the codebehind .cs file.
     
  3. Add this to the Page_Load method:
        protected void Page_Load(object sender, EventArgs e)
        {
            var item = Sitecore.Context.Item;
            if (Sitecore.Resources.Media.MediaManager.HasMediaContent(item))
            {
                string downloadUrl = 
                    string.Format("/sitecore/shell/download.aspx?file=db%3D{0}%26id%3D{1}%26la%3D{2}%26vs%3D{3}%26field%3D{4}", 
                    item.Database.Name, 
                    item.ID.ToString(), 
                    item.Language.Name, 
                    item.Version, 
                    item.Fields["blob"].ID.ToString());

                Response.Redirect(downloadUrl, true);
            }
        }

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

After compiling, go back into Sitecore and do this to implement the new Data Item Preview layout:

  1. Click Template Path from File you want this implemented on
    image
     
  2. Create a __Standard Values file (Builder –> Options – Standard Values)
    image
     
  3. Click on Presentation—>Layout—>Details
    image
     
  4. Click on “[No layout specified]”
    image
     
  5. Select your new “Data Item Preview” layout & save
    image

I’m sure there’s a better way, but this is working & the client is THRILLED to preview in one step.

 

.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, “Courier New”, courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }

, , , , , ,

No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: