<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>File Viewers</title><link>https://community.telligent.com/community/11/w/developer-training/65115/file-viewers</link><description /><dc:language>en-US</dc:language><generator>14.0.0.586 14</generator><item><title>File Viewers</title><link>https://community.telligent.com/community/11/w/developer-training/65115/file-viewers</link><pubDate>Tue, 04 Aug 2020 21:43:28 GMT</pubDate><guid isPermaLink="false">e35b8a44-ba19-41e5-9724-dc093d5ff16c</guid><dc:creator>Former Member</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65115/file-viewers#comments</comments><description>Current Revision posted to Developer Training by Former Member on 08/04/2020 21:43:28&lt;br /&gt;
&lt;p&gt;File Viewers allow the platform to&amp;nbsp;customize the display of uploaded files and Urls. &amp;nbsp;The &lt;a title="IFileviewer " href="/developers/w/developer90/50279/ifileviewer-plugin-type"&gt;IFileViewer&lt;/a&gt;&amp;nbsp;type defines which Urls or file extensions the viewer should handle and the output that should be displayed. &amp;nbsp;Verint Community ships with a wide array of file viewers, including Video, Audio, Url, Office document, PDF, Youtube and source code.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h2&gt;&lt;a id="Why_should_i_create_a_File_Viewer" name="Why_should_i_create_a_File_Viewer"&gt;&lt;/a&gt;Why should i create a File Viewer?&lt;/h2&gt;
&lt;p&gt;Instead of providing a link to download the file, a file viewer can display the contents of the file inline. &amp;nbsp;For example, instead of showing a hyperlink to a Youtube video, the Youtube file viewer displays that video inline and allows it to be played without leaving the community.&lt;/p&gt;
&lt;h2&gt;&lt;a id="Creating_a_File_Viewer" name="Creating_a_File_Viewer"&gt;&lt;/a&gt;Creating a File Viewer&lt;/h2&gt;
&lt;p&gt;To add support for a file viewer, implement the &lt;a href="/developers/w/developer90/50279/ifileviewer-plugin-type"&gt;IFileViewer&lt;/a&gt;&amp;nbsp;plugin type (which is found in the&amp;nbsp;Telligent.Evolution.Api.dll). The &lt;a href="/developers/w/developer90/50279/ifileviewer-plugin-type"&gt;IFileViewer&lt;/a&gt;&amp;nbsp;interface extends &lt;code&gt;IPlugin&lt;/code&gt; to add support custom file viewers.&lt;/p&gt;
&lt;p&gt;To begin, implement the &lt;code&gt;SupportedUrlPattern&lt;/code&gt;, &lt;code&gt;SupportedFileExtensions&lt;/code&gt; and &lt;code&gt;DefaultOrderNumber&lt;/code&gt; properties. &amp;nbsp;Our example file viewer will allow Vine embed Urls to be viewed in the community. &amp;nbsp;Since we are not supporting uploaded files with this file viewer, the&amp;nbsp;&lt;code&gt;SupportedFileExtensions&lt;/code&gt; property returns an empty collection. &amp;nbsp;The &lt;code&gt;SupportedUrlPattern&lt;/code&gt; property uses a regular expression to limit the file viewer to Urls containing the vine.co domain. &amp;nbsp;The &lt;code&gt;DefaultOrderNumber&lt;/code&gt; defines the order in which file viewers are checked against the&amp;nbsp;&lt;code&gt;SupportedFileExtensions&lt;/code&gt; and&amp;nbsp;&lt;code&gt;SupportedUrlPattern&lt;/code&gt; properties. &amp;nbsp;If two different file viewers were both capable of handling a file or Url, the one with the lower order number would take precedence.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public int DefaultOrderNumber 
{ 
    get { return 100; } 
}

public string SupportedUrlPattern
{
    get { return @&amp;quot;https?://vine\.co/&amp;quot;; }
}

public string[] SupportedFileExtensions 
{ 
    get { return new string[0]; } 
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Next, the &lt;code&gt;GetMediaType&lt;/code&gt; methods are implemented. &amp;nbsp;There are two methods, one for Urls being viewed and the other for files. &amp;nbsp;Our file viewer does not support files, so we can throw a &lt;code&gt;FileViewerNotSupportedException&lt;/code&gt; to indicate that to the platform. &amp;nbsp;The &lt;code&gt;GetMediaType&lt;/code&gt;&amp;nbsp;method that receives a Url will throw a &lt;code&gt;FileViewerNotSupportedException &lt;/code&gt;when previewing the Url, the platform will handle the preview for the File Viewer. &amp;nbsp;When viewing the method will return Video.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public FileViewerMediaType GetMediaType(ICentralizedFile file, IFileViewerOptions options)
{
    throw new FileViewerNotSupportedException();
}

public FileViewerMediaType GetMediaType(Uri url, IFileViewerOptions options)
{
    if (options.ViewType == FileViewerViewType.Preview)
        throw new FileViewerNotSupportedException();

    return FileViewerMediaType.Video;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Lastly, the &lt;code&gt;Render&lt;/code&gt; methods are implemented. &amp;nbsp;Again since we do not support viewing files in our example, this method will throw a &lt;code&gt;FileViewerNotSupportedException&lt;/code&gt;. &amp;nbsp;The &lt;code&gt;Render&lt;/code&gt; method that&amp;nbsp;receives a Url as a parameter, will have two code paths. &amp;nbsp;Our sample does not provide a preview image specific to Vine, instead we can return a &lt;code&gt;FileViewerNotSupportedException&lt;/code&gt;. &amp;nbsp;The platform will provide a default image preview. &amp;nbsp;When viewing the video, the method will return an IFrame with the vine Url that will display the vine video inline in the content.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public string Render(ICentralizedFile file, IFileViewerOptions options)
{
    throw new FileViewerNotSupportedException();
}

public string Render(Uri url, IFileViewerOptions options)
{
    var uiApi = Telligent.Evolution.Extensibility.Apis.Get&amp;lt;IUI&amp;gt;();

    if (options.ViewType == FileViewerViewType.Preview)
    {
        throw new FileViewerNotSupportedException();
    }
    else
    {
        var width = options.Width.HasValue ? options.Width.Value : 0;
        var height = options.Height.HasValue ? options.Height.Value : 0;
        return string.Format(&amp;quot;&amp;lt;iframe src=\&amp;quot;{0}\&amp;quot; width=\&amp;quot;{1}\&amp;quot; height=\&amp;quot;{2}\&amp;quot; frameborder=\&amp;quot;0\&amp;quot; scrolling=\&amp;quot;no\&amp;quot; /&amp;gt;&amp;quot;
            , Globals.EnsureHtmlEncoded(url.ToString()), width, height);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Source_Code" name="Source_Code"&gt;&lt;/a&gt;Source Code&lt;/h2&gt;
&lt;p&gt;Once the completed plugin is enabled, vine.co embed Urls will now be displayed inline in your content. &amp;nbsp;Here is the full class including the &lt;code&gt;IPlugin &lt;/code&gt;implementation.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;using System;
using System.Web;
using Telligent.DynamicConfiguration.Components;
using Telligent.Evolution.Components;
using Telligent.Evolution.Extensibility.Api.Version1;
using Telligent.Evolution.Extensibility.Storage.Version1;
using Telligent.Evolution.Extensibility.UI.Version1;
using Telligent.Evolution.Extensibility.Version1;

namespace Examples
{
    public class VineEmbedFileViewer : Telligent.Evolution.Extensibility.UI.Version1.IFileViewer
    {
        #region IPlugin Members
        public string Name {
            get { return &amp;quot;Vine File Viewer&amp;quot;; }
        }

        public string Description {
            get { return &amp;quot;Allows embedding of Vine videos&amp;quot;; }
        }
        
        public void Initialize()
        {
        }
        #endregion

        #region IFileViewer Members

        public int DefaultOrderNumber { get { return 100; } }

        public string SupportedUrlPattern
        {
            get { return @&amp;quot;http[s]?://vine\.co/&amp;quot;; }
        }
        public string[] SupportedFileExtensions { get { return new string[0]; } }

        public string Render(ICentralizedFile file, IFileViewerOptions options)
        {
            throw new FileViewerNotSupportedException();
        }

        public string Render(Uri url, IFileViewerOptions options)
        {
            var uiApi = Telligent.Evolution.Extensibility.Apis.Get&amp;lt;IUI&amp;gt;();

            if (options.ViewType == FileViewerViewType.Preview)
            {
                throw new FileViewerNotSupportedException();
            }
            else
            {
                var width = options.Width.HasValue ? options.Width.Value : 0;
                var height = options.Height.HasValue ? options.Height.Value : 0;
                return string.Format(&amp;quot;&amp;lt;iframe src=\&amp;quot;{0}\&amp;quot; width=\&amp;quot;{1}\&amp;quot; height=\&amp;quot;{2}\&amp;quot; frameborder=\&amp;quot;0\&amp;quot; scrolling=\&amp;quot;no\&amp;quot; /&amp;gt;&amp;quot;
                    , Globals.EnsureHtmlEncoded(url.ToString()), width, height);
            }
        }

        public FileViewerMediaType GetMediaType(ICentralizedFile file, IFileViewerOptions options)
        {
            throw new FileViewerNotSupportedException();
        }

        public FileViewerMediaType GetMediaType(Uri url, IFileViewerOptions options)
        {
            if (options.ViewType == FileViewerViewType.Preview)
                throw new FileViewerNotSupportedException();

            return FileViewerMediaType.Video;
        }

        #endregion

    }
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: IFileViewer, file viewer&lt;/div&gt;
</description></item><item><title>File Viewers</title><link>https://community.telligent.com/community/11/w/developer-training/65115/file-viewers/revision/1</link><pubDate>Thu, 13 Jun 2019 19:28:50 GMT</pubDate><guid isPermaLink="false">e35b8a44-ba19-41e5-9724-dc093d5ff16c</guid><dc:creator>Ben Tiedt</dc:creator><comments>https://community.telligent.com/community/11/w/developer-training/65115/file-viewers#comments</comments><description>Revision 1 posted to Developer Training by Ben Tiedt on 06/13/2019 19:28:50&lt;br /&gt;
&lt;p&gt;File Viewers allow the platform to&amp;nbsp;customize the display of uploaded files and Urls. &amp;nbsp;The &lt;a title="IFileviewer " href="/developers/w/developer90/50279/ifileviewer-plugin-type"&gt;IFileViewer&lt;/a&gt;&amp;nbsp;type defines which Urls or file extensions the viewer should handle and the output that should be displayed. &amp;nbsp;Telligent Community ships with a wide array of file viewers, including Video, Audio, Url, Office document, PDF, Youtube and source code.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;h2&gt;&lt;a id="Why_should_i_create_a_File_Viewer" name="Why_should_i_create_a_File_Viewer"&gt;&lt;/a&gt;Why should i create a File Viewer?&lt;/h2&gt;
&lt;p&gt;Instead of providing a link to download the file, a file viewer can display the contents of the file inline. &amp;nbsp;For example, instead of showing a hyperlink to a Youtube video, the Youtube file viewer displays that video inline and allows it to be played without leaving the community.&lt;/p&gt;
&lt;h2&gt;&lt;a id="Creating_a_File_Viewer" name="Creating_a_File_Viewer"&gt;&lt;/a&gt;Creating a File Viewer&lt;/h2&gt;
&lt;p&gt;To add support for a file viewer, implement the &lt;a href="/developers/w/developer90/50279/ifileviewer-plugin-type"&gt;IFileViewer&lt;/a&gt;&amp;nbsp;plugin type (which is found in the&amp;nbsp;Telligent.Evolution.Api.dll). The &lt;a href="/developers/w/developer90/50279/ifileviewer-plugin-type"&gt;IFileViewer&lt;/a&gt;&amp;nbsp;interface extends &lt;code&gt;IPlugin&lt;/code&gt; to add support custom file viewers.&lt;/p&gt;
&lt;p&gt;To begin, implement the &lt;code&gt;SupportedUrlPattern&lt;/code&gt;, &lt;code&gt;SupportedFileExtensions&lt;/code&gt; and &lt;code&gt;DefaultOrderNumber&lt;/code&gt; properties. &amp;nbsp;Our example file viewer will allow Vine embed Urls to be viewed in the community. &amp;nbsp;Since we are not supporting uploaded files with this file viewer, the&amp;nbsp;&lt;code&gt;SupportedFileExtensions&lt;/code&gt; property returns an empty collection. &amp;nbsp;The &lt;code&gt;SupportedUrlPattern&lt;/code&gt; property uses a regular expression to limit the file viewer to Urls containing the vine.co domain. &amp;nbsp;The &lt;code&gt;DefaultOrderNumber&lt;/code&gt; defines the order in which file viewers are checked against the&amp;nbsp;&lt;code&gt;SupportedFileExtensions&lt;/code&gt; and&amp;nbsp;&lt;code&gt;SupportedUrlPattern&lt;/code&gt; properties. &amp;nbsp;If two different file viewers were both capable of handling a file or Url, the one with the lower order number would take precedence.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public int DefaultOrderNumber 
{ 
    get { return 100; } 
}

public string SupportedUrlPattern
{
    get { return @&amp;quot;https?://vine\.co/&amp;quot;; }
}

public string[] SupportedFileExtensions 
{ 
    get { return new string[0]; } 
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Next, the &lt;code&gt;GetMediaType&lt;/code&gt; methods are implemented. &amp;nbsp;There are two methods, one for Urls being viewed and the other for files. &amp;nbsp;Our file viewer does not support files, so we can throw a &lt;code&gt;FileViewerNotSupportedException&lt;/code&gt; to indicate that to the platform. &amp;nbsp;The &lt;code&gt;GetMediaType&lt;/code&gt;&amp;nbsp;method that receives a Url will throw a &lt;code&gt;FileViewerNotSupportedException &lt;/code&gt;when previewing the Url, the platform will handle the preview for the File Viewer. &amp;nbsp;When viewing the method will return Video.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public FileViewerMediaType GetMediaType(ICentralizedFile file, IFileViewerOptions options)
{
    throw new FileViewerNotSupportedException();
}

public FileViewerMediaType GetMediaType(Uri url, IFileViewerOptions options)
{
    if (options.ViewType == FileViewerViewType.Preview)
        throw new FileViewerNotSupportedException();

    return FileViewerMediaType.Video;
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Lastly, the &lt;code&gt;Render&lt;/code&gt; methods are implemented. &amp;nbsp;Again since we do not support viewing files in our example, this method will throw a &lt;code&gt;FileViewerNotSupportedException&lt;/code&gt;. &amp;nbsp;The &lt;code&gt;Render&lt;/code&gt; method that&amp;nbsp;receives a Url as a parameter, will have two code paths. &amp;nbsp;Our sample does not provide a preview image specific to Vine, instead we can return a &lt;code&gt;FileViewerNotSupportedException&lt;/code&gt;. &amp;nbsp;The platform will provide a default image preview. &amp;nbsp;When viewing the video, the method will return an IFrame with the vine Url that will display the vine video inline in the content.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;public string Render(ICentralizedFile file, IFileViewerOptions options)
{
    throw new FileViewerNotSupportedException();
}

public string Render(Uri url, IFileViewerOptions options)
{
    var uiApi = Telligent.Evolution.Extensibility.Apis.Get&amp;lt;IUI&amp;gt;();

    if (options.ViewType == FileViewerViewType.Preview)
    {
        throw new FileViewerNotSupportedException();
    }
    else
    {
        var width = options.Width.HasValue ? options.Width.Value : 0;
        var height = options.Height.HasValue ? options.Height.Value : 0;
        return string.Format(&amp;quot;&amp;lt;iframe src=\&amp;quot;{0}\&amp;quot; width=\&amp;quot;{1}\&amp;quot; height=\&amp;quot;{2}\&amp;quot; frameborder=\&amp;quot;0\&amp;quot; scrolling=\&amp;quot;no\&amp;quot; /&amp;gt;&amp;quot;
            , Globals.EnsureHtmlEncoded(url.ToString()), width, height);
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;h2&gt;&lt;a id="Source_Code" name="Source_Code"&gt;&lt;/a&gt;Source Code&lt;/h2&gt;
&lt;p&gt;Once the completed plugin is enabled, vine.co embed Urls will now be displayed inline in your content. &amp;nbsp;Here is the full class including the &lt;code&gt;IPlugin &lt;/code&gt;implementation.&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="csharp"&gt;using System;
using System.Web;
using Telligent.DynamicConfiguration.Components;
using Telligent.Evolution.Components;
using Telligent.Evolution.Extensibility.Api.Version1;
using Telligent.Evolution.Extensibility.Storage.Version1;
using Telligent.Evolution.Extensibility.UI.Version1;
using Telligent.Evolution.Extensibility.Version1;

namespace Examples
{
    public class VineEmbedFileViewer : Telligent.Evolution.Extensibility.UI.Version1.IFileViewer
    {
        #region IPlugin Members
        public string Name {
            get { return &amp;quot;Vine File Viewer&amp;quot;; }
        }

        public string Description {
            get { return &amp;quot;Allows embedding of Vine videos&amp;quot;; }
        }
        
        public void Initialize()
        {
        }
        #endregion

        #region IFileViewer Members

        public int DefaultOrderNumber { get { return 100; } }

        public string SupportedUrlPattern
        {
            get { return @&amp;quot;http[s]?://vine\.co/&amp;quot;; }
        }
        public string[] SupportedFileExtensions { get { return new string[0]; } }

        public string Render(ICentralizedFile file, IFileViewerOptions options)
        {
            throw new FileViewerNotSupportedException();
        }

        public string Render(Uri url, IFileViewerOptions options)
        {
            var uiApi = Telligent.Evolution.Extensibility.Apis.Get&amp;lt;IUI&amp;gt;();

            if (options.ViewType == FileViewerViewType.Preview)
            {
                throw new FileViewerNotSupportedException();
            }
            else
            {
                var width = options.Width.HasValue ? options.Width.Value : 0;
                var height = options.Height.HasValue ? options.Height.Value : 0;
                return string.Format(&amp;quot;&amp;lt;iframe src=\&amp;quot;{0}\&amp;quot; width=\&amp;quot;{1}\&amp;quot; height=\&amp;quot;{2}\&amp;quot; frameborder=\&amp;quot;0\&amp;quot; scrolling=\&amp;quot;no\&amp;quot; /&amp;gt;&amp;quot;
                    , Globals.EnsureHtmlEncoded(url.ToString()), width, height);
            }
        }

        public FileViewerMediaType GetMediaType(ICentralizedFile file, IFileViewerOptions options)
        {
            throw new FileViewerNotSupportedException();
        }

        public FileViewerMediaType GetMediaType(Uri url, IFileViewerOptions options)
        {
            if (options.ViewType == FileViewerViewType.Preview)
                throw new FileViewerNotSupportedException();

            return FileViewerMediaType.Video;
        }

        #endregion

    }
}
&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: IFileViewer, file viewer&lt;/div&gt;
</description></item></channel></rss>