Manipulate Telerik’s RadUpload control Filename when Uploading Files – Sitefinity

Bundled in with the Sitefinity CMS suite are many of Telerik’s ASP.Net controls, and we will be focusing on the Telerik RadUpload control in this post.

When creating some sort of upload control, it’s always nice to be able to control the filename of the file being uploaded within the server-side programming language. To do so using Telerik’s RadUpload control and C#, follow the very simple way.

You will see within the ImgUpload.ascx control markup that the RadUpload control is being added to the page, referencing the Telerik libraries. Notice the “AllowedFileExtensions” property – this is a great way to control what gets uploaded without writing any C# code!

The C# code is tailored to add a DateTime.Now Ticks string to the end of the filename, and then programmatically add the extension back on to it. This creates an ultra-unique filename, and will not overwrite any other files that are uploaded (images in this example). This is a great way that Sitefinity can leverage the different controls that are provided by Telerik, and make adding files to the Sitefintiy filesystem much more easy than the typical ASP.Net way.


<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ImgUpload.ascx.cs" Inherits="Custom_UserControls_ImgUpload" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>

<telerik:RadUpload ID="myRadUploadImg" runat="server" AllowedFileExtensions=".png,.jpg,.gif"
    ControlObjectsVisibility="None" MaxFileInputsCount="1" Skin="Windows7">


if (myRadUploadImg.UploadedFiles.Count > 0)
                    //check image name and do not overwrite duplicates.
                    DateTime getTimeTicks = DateTime.Now;
                    string timeTicks = getTimeTicks.Ticks.ToString();
                    foreach (UploadedFile f in myRadUploadImg.UploadedFiles)
                        f.SaveAs("C:\\inetpub\\wwwroot\\images\\" + f.GetNameWithoutExtension() + timeTicks + f.GetExtension(), false);
                    recipe.RecipeImage = myRadUploadImg.UploadedFiles[0].GetNameWithoutExtension() + timeTicks + myRadUploadImg.UploadedFiles[0].GetExtension();
Posted in, C#, Sitefinity, Telerik
  • Gus

    What for god’s sake is “recipe” D:

  • Shokung

    what “recipe” is?

  • Wse