Thread is closed for posting
2 posts, 0 answers
  1. Marnix Bouwman
    Marnix Bouwman avatar
    22 posts
    Member since:
    Nov 2009

    Posted 04 Apr 2011 Link to this post

    Hi, I'm using Radupload and trying to save a record to the database like so on a button click event:

    If RadUpload1.UploadedFiles.Count > 0 Then
            .Picture = RadUpload1.UploadedFiles(0).FileName
            .Picture = ""
    End If

    However, I would also like to change the filename when the file already exists. So I added the FileExists function:
            Protected Sub RadUpload1_FileExists(ByVal sender As Object, ByVal e As UploadedFileEventArgs) Handles RadUpload1.FileExists
                Dim counter As Integer = 1
                Dim file As UploadedFile = e.UploadedFile
                Dim targetFolder As String = Server.MapPath(RadUpload1.TargetFolder)
                Dim targetFileName As String = System.IO.Path.Combine(targetFolder, file.GetNameWithoutExtension & counter & file.GetExtension)
                While System.IO.File.Exists(targetFileName)
                    counter += 1
                    targetFileName = System.IO.Path.Combine(targetFolder, file.GetNameWithoutExtension & counter & file.GetExtension)
                End While
            End Sub

    This results in changing the filename to picture1.jpg if picture.jpg already exists.
    However, it will still save picture.jpg to the database.
    How can I make sure it will be updated in the correct way?
  2. Dimitar Terziev
    Dimitar Terziev avatar
    1266 posts

    Posted 07 Apr 2011 Link to this post

    Hi Marnix,

    In general this FileExist event is fired when you have either TargetFolder or TargetPhysicalFolder set and OverwriteExistingFiles property is set to False.

    If you save your files to a database, this event won't prevent files with duplicating names to be saved. This event is used only when the files are saved on the file system.

    Since you haven't provided the code used to insert records to a database, my suggestion is the following. In this button click event handler function you will check, if there is already a file with such name and if so you will change the name of the currently uploaded file manually and then save it to the database.

    Best wishes,
    Dimitar Terziev
    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. DevCraft R3 2016 release webinar banner
Back to Top