Frederik Vig – ASP.NET developer

Follow me

Posts tagged ‘SlideShare’

SlideShare Dynamic Content

In previous posts I’ve blogged about the SlideShare API. In this post I’m going to show how you can use it to create a Dynamic Content Plugin that lets your editors choose a presentation from SlideShare.net and display it on their web page.

Before we start I recommend that you read through my SlideShare API post and also browse the code to get a better picture of what we can do and what is available for you to extend and build on.

I would like to thank Peter Sunna for his excellent blog post Display youtube videos in episerver using dynamic content – which this code is based on.

The plugin consists of two parts, an admin plugin for storing settings, and the dynamic content plugin for choosing a presentation.

Admin plugin

SlideShare Admin plugin
Take a look at my post Creating an EPiServer Plugin for more information.

To get the API and Shared Secret keys go to the Apply for API Keys page and fill out the form. You should then receive an email with both keys.

Dynamic content plugin

SlideShare Dynamic Content plugin

With paging:
SlideShare Dynamic Content plugin with paging

I’ve only added the ability for editors to choose a presentation from one user. But if you take a look at the SlideShare API, you see all the other methods we can use to improve this even further.

View mode

Installation

  1. Download and extract FV.DynamicSlideSharea
  2. Open up the Install folder
  3. Copy the dll files from the bin folder to your sites bin folder
  4. Copy the language file from the lang folder
  5. Copy the whole FV.DynamicSlideShare folder
  6. Register the dynamic content plugin in your sites episerver.config file
    <dynamicContent>
    	<controls>
    		...
    		<add description="DynamicSlideShare" name="DynamicSlideShare" type="FV.DynamicSlideShare.Plugins.DynamicSlideShare, FV.DynamicSlideShare"/>
    	</controls>
    </dynamicContent>

Remember to fill out the settings in admin mode, under Tools and SlideShare Admin.

Apply for API and Security key.

Download FV.DynamicSlideShare from EPiCode, or SVN Checkout the source code.

SlideShare .NET API Wrapper

In a recent project I had to work with the SlideShare API. Thankfully there was some good documentation to get me started, and even a .NET wrapper for the first version of the API.

From SlideShare

SlideShare is a business media site for sharing presentations, documents and pdfs.

After downloading and playing around with the code I decided to upgrade it to version 2 of the API. I encourage you to take a look at the documentation if you haven’t, to see what’s new in version 2 of the API, and what’s available.

SlideShare API Wrapper Methods

Here are the methods that I’ve exposed and made available for you to use. Big thanks to Brian Grinstead for his blog post Multipart Form Post in C# and for Gaurav Gupta for creating the wrapper class for the first version, which this code is based on.

  • GetSlideshow
  • GetSlideshowsForTag
  • GetSlideshowsForGroup
  • GetSlideshowsForUser
  • SlideshowSearch
  • GetUserGroups
  • GetUserContacts
  • GetUserTags
  • EditSlideshow
  • DeleteSlideshow
  • UploadSlideshow

To use it simply download the code (see link at the bottom of this post), copy the SlideShareAPI.dll into your bin folder and make a reference to it in your project. After you’ve done that you’ll be able to create an instance of the SlideShare class which will expose the methods above.

Remember that you also need an API Key and Shared Secret. Go to the Apply for API Keys page and fill out the form. You should then receive an email with both keys.

Example

Lets get some slideshows that are tagged with web, bind them to a Repeater control and display them to the user.

using System;
using System.Linq;
using System.Xml.Linq;
using SlideShareAPI;
 
namespace FV.Templates.FV.Pages
{
    public partial class SlideShareTest : System.Web.UI.Page
    {
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
 
            var slideShare = new SlideShare("API Key", "Shared secret");
 
            var xml = XElement.Parse(slideShare.GetSlideshowsForTag("web", 0, 10));
 
            var slideshows = from slideshare in xml.Elements("Slideshow")
                            select new
                            {
                                Title = slideshare.Element("Title").Value,
                                Description = slideshare.Element("Description").Value,
                                EmbedCode = slideshare.Element("Embed").Value
                            };
 
            rptSlideshows.DataSource = slideshows;
            rptSlideshows.DataBind();
        }
    }
}

I use Linq to XML and create anonymous objects that I then databind to my Repeater.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SlideShareTest.aspx.cs" Inherits="FV.Templates.FV.Pages.SlideShareTest" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:Repeater runat="server" ID="rptSlideshows">
    <HeaderTemplate><ul></HeaderTemplate>
    <ItemTemplate>
        <li>
        <h3><%# HttpUtility.HtmlEncode(Eval("Title").ToString()) %></h3>
        <p><%# HttpUtility.HtmlEncode(Eval("Description").ToString()) %></p>
        <%# HttpUtility.HtmlDecode(Eval("EmbedCode").ToString())%>
        </li>
    </ItemTemplate>
    <FooterTemplate></ul></FooterTemplate>
</asp:Repeater>
    </form>
</body>
</html>

Most of the code is commented and available through Visual Studio Intellisense. You can also go through and change the code to your needs.

Download the code

© Copyright Frederik Vig. Based on Fluid Blue theme