More in this section

Forums / General Discussions / Image Gallery - Overwrite existing image during upload?

Image Gallery - Overwrite existing image during upload?

3 posts, 0 answered
  1. Anthony
    Anthony avatar
    15 posts
    03 Sep 2010
    14 Feb 2011
    Link to this post
    I understand that Sitefinity will store images in the database, so upon upload an image is assigned a GUID and is no longer unique identified by name.  However, users of the system are expecting that when they upload a file with a name that already exists in the gallery they uploading to they will be prompted to overwrite the existing file.  Is there somehow to set this as an option for the Image Gallery module, or is this functionality not supported?
  2. Radoslav Georgiev
    Radoslav Georgiev avatar
    3370 posts
    01 Feb 2016
    16 Feb 2011
    Link to this post
    Hi Anthony,

    There is a replace image button when you are editing a widget, which lets you reupload the image. Please refer to attached screen shot.

    Best wishes,
    Radoslav Georgiev
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Abhilash Shamsunder
    Abhilash Shamsunder avatar
    10 posts
    05 Apr 2010
    28 Jan 2013 in reply to Anthony
    Link to this post

    May be you would have found a solution for this. But, here's a custom library provider that helps you overwrite the documents.
    Note: This is for documents library only. You can modify this for image provider.

    using System;
    using System.Reflection;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Diagnostics;
    using Telerik.Sitefinity.Fluent;
    using Telerik.Sitefinity;
    namespace SitefinityWebApp.Custom
        public class LibraryProvider : Telerik.Sitefinity.Modules.Libraries.Data.OpenAccessLibrariesProvider
            public LibraryProvider() : base() { }
            /// <summary>
            /// </summary>
            /// <param name="content"></param>
            /// <param name="source"></param>
            /// <param name="extension"></param>
            public override void Upload(Telerik.Sitefinity.Libraries.Model.MediaContent content, System.IO.Stream source, string extension)
                if (content is Telerik.Sitefinity.Libraries.Model.Document)
                    DocumentOverwrite(content, source, extension);
                    base.Upload(content, source, extension);
            private void DocumentOverwrite(Telerik.Sitefinity.Libraries.Model.MediaContent content, System.IO.Stream source, string extension)
                var masterId = GetMasterId(content, extension);
                if (masterId.HasValue)
                    Publish(masterId.Value, source, extension);
                    //Get master doc
                    var master = GetDocument(masterId.Value);
                    //Delete new content
                    content = master;
                    base.Upload(content, source, extension);
            private void Publish(Guid masterId, System.IO.Stream source, string extension)
                var manager = Telerik.Sitefinity.Modules.Libraries.LibrariesManager.GetManager();
                var master = manager.GetDocument(masterId);
                //Create draft version of master
                var temp = (Telerik.Sitefinity.Libraries.Model.MediaContent)manager.Lifecycle.CheckOut(master);
                //Upload file into draft
                base.UploadDataOnly(temp, source);
                //Check in draft, updates master
            private Guid? GetMasterId(Telerik.Sitefinity.Libraries.Model.MediaContent content, string extension)
                Guid? id = null;
                Telerik.Sitefinity.Libraries.Model.Document master = null;
                using (var fluent = App.WorkWith())
                    master = fluent
                        .Where(doc => doc.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master)
                            doc =>
                                doc.Title == content.Title
                                && doc.Extension == extension
                                && doc.Id != content.Id);
                if (master != null)
                    id = master.Id;
                return id;

    Not sure why, but this request has been in for many years now yet sitefinity has not implemented a solution.

    Hope this helps.
3 posts, 0 answered