Image Gallery - Overwrite existing image during upload?
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?
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
Hi,
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);
else
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
Delete((Telerik.Sitefinity.Libraries.Model.Document)content);
//Overwrite
content = master;
else
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
manager.Lifecycle.CheckIn(temp);
//Publish
manager.Lifecycle.Publish(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
.DocumentLibrary(content.Parent.Id)
.Documents()
.Get()
.Where(doc => doc.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Master)
.ToList()
.FirstOrDefault(
doc =>
doc.Title == content.Title
&& doc.Extension == extension
&& doc.Id != content.Id);
if (master != null)
id = master.Id;
return id;