+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / RadUpload FileExists not firing

RadUpload FileExists not firing

5 posts, 0 answered
  1. Jason
    Jason avatar
    21 posts
    Registered:
    12 Nov 2009
    30 Mar 2010
    Link to this post
    I'm having issues getting the FileExists event to fire for RadUpload.  It has to be something silly but I've pretty much got the sample code line-for-line and yet still no file rename happens.  when I set a break-point and debug the code never even enters the FileExists code block.  Files will get uploaded to the folder, except if the file already exists it will not overwrite but it will not rename.
    <telerik:RadUpload
                              ID="RadUpload1" runat="server"
                              MaxFileInputsCount="5"
                              TargetFolder="/web-upload"
                              OverwriteExistingFiles="false" />

    and the .cs is:
    protected void RadUpload1_FileExists(object sender, Telerik.Web.UI.Upload.UploadedFileEventArgs e)
            {
                int counter = 1;
     
                UploadedFile file = e.UploadedFile;
     
                string targetFolder = Server.MapPath(RadUpload1.TargetFolder);
     
                string targetFileName = Path.Combine(targetFolder,
                    file.GetNameWithoutExtension() + counter.ToString() + file.GetExtension());
     
                while (System.IO.File.Exists(targetFileName))
                {
                    counter++;
                    targetFileName = Path.Combine(targetFolder,
                        file.GetNameWithoutExtension() + counter.ToString() + file.GetExtension());
                }
     
                file.SaveAs(targetFileName);
            }
  2. Jason
    Jason avatar
    21 posts
    Registered:
    12 Nov 2009
    31 Mar 2010
    Link to this post
    Just to followup and close thread.....couldn't get FileExists to fire so I wrote my own method.
  3. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    05 Apr 2010
    Link to this post
    Hi Jason,

    Most probably you are subscribing for the event to late. You need to subscribe for FileExists, OnLoad as the code below shows.

    protected override void OnLoad(EventArgs e)
      {
          base.OnLoad(e);
          if (Page.IsPostBack && RadUpload1 !=null && RadUpload1.UploadedFiles.Count > 0)
          {
              this.RadUpload1.FileExists += new Telerik.Web.UI.Upload.UploadedFileEventHandler(RadUpload1_FileExists);
          }
      }
     void RadUpload1_FileExists(object sender, Telerik.Web.UI.Upload.UploadedFileEventArgs e)
      {
          
      }


    Best wishes,
    Ivan Dimitrov
    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.
  4. görkem
    görkem avatar
    1 posts
    Registered:
    21 Jun 2012
    22 Feb 2011
    Link to this post
    Hello, i have the same problem but my radupload in RadAjaxPanel

    would you mind sending the code in vb ?
  5. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    24 Feb 2011
    Link to this post
    Hello,

    You can use the converter tool to switch the code to VB.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Register for webinar
5 posts, 0 answered