Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

Ektron Upload File Into Library

Posted on February 18, 2015October 26, 2015 By David Kittell

I found and modified code to create an Ektron Library File Upload function.
This function allows some customization:

  • Defined Folder ID
    • In this code I manually set the folder ID but effectively
      you could have a drop down list of folders to select the folder
      (see DMS Widget)
  • Content Title
    • This is used in the Ektron Library as the title of the
      file
  • File Name
    • This is used in the Ektron Library as the filename and part
      of the filepath
  • File Upload Control
    • This is used in the event that you want to have more than
      one upload control
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LibraryUpload.aspx.cs" Inherits="LibraryUpload" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Library Upload</title>

</head>
<body>
    <form id="form1" runat="server">

        <h1>New Division</h1>
        <asp:ValidationSummary runat="server" ID="vasFileUpload" ValidationGroup="FileUpload" ForeColor="#81060C" />

        <asp:Label ID="lblDivisionID" runat="server" Text="Division ID:" AssociatedControlID="txtDivisionID" /><br />
        <asp:TextBox ID="txtDivisionID" runat="server" />
        <asp:RequiredFieldValidator ID="rfvDivisionID" runat="server" ControlToValidate="txtDivisionID" Display="None"
            ErrorMessage="The Division ID field is required, please complete the information."
            ValidationGroup="FileUpload" /><br />
        <asp:Label ID="lblFile" runat="server" Text="File:" AssociatedControlID="fupFile" /><br />
        <asp:FileUpload ID="fupFile" runat="server" />
        <br />
        <asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" ValidationGroup="FileUpload" CausesValidation="true" />

        <p><asp:Literal ID="ltlMessage" runat="server" /></p>

    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.IO;

using Ektron.Cms;
using Ektron.Cms.API;
using Ektron.Cms.Common;
using Ektron.Cms.Content;
using Ektron.Cms.Framework.Content;
using Ektron.Cms.Framework.Organization;
using Ektron.Cms.Framework;
using Ektron.Cms.Organization;

public partial class LibraryUpload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }


    protected void btnUpload_Click(object sender, EventArgs e)
    {
        //Library Upload Upload
        EktronLibraryUpload(167, txtDivisionID.Text, txtDivisionID.Text + ".pdf", fupFile);
    }

    protected void EktronLibraryUpload(long lFolderID, string sContentTitle, string sFileName, FileUpload fupFile)
    {

        // initialize framework.
        Ektron.Cms.API.Library eLibraryAPI = new Ektron.Cms.API.Library();
        LibraryManager eLibraryMgr = new LibraryManager();

        // determine if the item already exists.
       // Ektron.Cms.Content.LibraryCriteria eLibraryCriteria = new Ektron.Cms.Content.LibraryCriteria();

        #region Upload the file to Ektron
        Ektron.Cms.LibraryConfigData eLibraryConfigData = eLibraryAPI.GetLibrarySettings(lFolderID);

        // Set filename server path
        string sFileServerPath = Server.MapPath(eLibraryConfigData.FileDirectory);

        // Set filename to original file name (whatever the user has named the file) if a custom file name is not specified
        if (sFileName == "")
        {
            sFileName = Path.GetFileName(fupFile.FileName);
        }

        try
        {
            Ektron.Cms.LibraryData item = new Ektron.Cms.LibraryData()
            {
                Title = sContentTitle,
                ParentId = lFolderID,
                FileName = sFileServerPath + sFileName,
                File = fupFile.FileBytes
            };

            if (fupFile.PostedFile.ContentType == "application/pdf")
            {
                eLibraryMgr.Add(item);
                ltlMessage.Text = "Library item added with ID = " + item.Id.ToString();
            }
            else
            {
                ltlMessage.Text = "Not added. File must be a PDF.";
            }
        }
        catch (Exception ex)
        {
            ltlMessage.Text = "Not added, " + ex.Message;
        }
        #endregion Upload the file to Ektron
    }
}

References:

  • Ektron Developer Reference
  • Ektron Developer Forum
Originally Posted on February 18, 2015
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

C# ASPX C# Ektron Code CSharp Ektron

Post navigation

Previous post
Next post

Related Posts

Create / Delete SQLite Database Indexes

Posted on September 27, 2013December 30, 2015

‘Create Index Sub CreateIndex(SQL As SQL, TableName As String, IndexName As String, Fields As String, Unique As Boolean) Dim query, uni As String uni = "" If Unique=True Then uni = "UNIQUE" query = "CREATE " & uni & " INDEX IF NOT EXISTS " & IndexName & " ON…

Read More

MySQL – Get Max Length of Column

Posted on October 29, 2015October 29, 2015

Similar to Max Length of Data In Column – MSSQL this query will do the same for MySQL Replace host (column) along with hosts (table) with what you’d like to check SELECT host ,LENGTH(host) AS mlen FROM hosts ORDER BY mlen DESC All information on this site is shared with…

Read More

PowerShell – Get/Set Windows Date/Time from NTP

Posted on December 3, 2015February 12, 2016

Sometimes w32Time is not available or practical so we get this PowerShell script to pull NTP date/time and set the Windows Date/Time <# Majority of code is from: Chris Warwick, @cjwarwickps, August 2012 chrisjwarwick.wordpress.com #> $sNTPServer = ‘pool.ntp.org’ function Get-NTPDateTime ([string] $sNTPServer) { $StartOfEpoch=New-Object DateTime(1900,1,1,0,0,0,[DateTimeKind]::Utc) [Byte[]]$NtpData = ,0 * 48…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • C# - Start/Stop/Restart Services
  • MacPorts / HomeBrew - Rip CD tracks from terminal
  • PowerShell - Show File Extensions
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
©2025 David Kittell | WordPress Theme by SuperbThemes