upload handler .... new filename not changing

2 posts, 0 answers
  1. David Ocasio
    David Ocasio avatar
    147 posts
    Member since:
    Nov 2009

    Posted 27 Jul 2015 Link to this post

    I am using the following pasted code for the handler. It was authored quite awhile ago. The new filename for multiple files is not changing. That is if two files are uploaded at the same time, only one filename is returned for both.

    How can I adjust this to fix that.


    Public Class agUploadHandler
        Inherits Telerik.Windows.RadUploadHandler
        Private newfilename As String = String.Empty
        Public Overrides Property TargetPhysicalFolder() As String
                Return Security.SystemDirs(Datum.eSystemDirs.Upload)
                Return MyBase.TargetPhysicalFolder
            End Get
            Set(ByVal value As String)
                MyBase.TargetPhysicalFolder = Security.SystemDirs(Datum.eSystemDirs.Upload)
            End Set
        End Property
        Public Overrides Function GetAssociatedData() As System.Collections.Generic.Dictionary(Of String, Object)
            Dim dict As System.Collections.Generic.Dictionary(Of String, Object) = MyBase.GetAssociatedData
            If IsNothing(newfilename) = False AndAlso newfilename <> String.Empty Then
                dict.Add("NewFileName", newfilename)
            End If
            Return dict
        End Function
        Protected ReadOnly Property Security() As Datum.ISecurity
                ' this was shoved on the thread at login
                If IsNothing(_Security) Then
                    _Security = Datum.EntityHelper.getSecurity(True)
                End If
                Return _Security
            End Get
        End Property
        Protected _Security As Datum.ISecurity = Nothing
        Public Overrides Sub ProcessStream()
            If IsNewFileRequest() Then
                ResultChunkTag = Guid.NewGuid.ToString
            ElseIf FormChunkTag <> Nothing Then
                ResultChunkTag = FormChunkTag
            End If
        End Sub
        Public Overrides Function GetFilePath(ByVal fileName As String) As String
            fileName = MyBase.GetFilePath(GetFilename(fileName))
            Return fileName
        End Function
        Private Shadows Function GetFilename(ByVal filename As String) As String
            If ResultChunkTag <> Nothing Then
                filename = ResultChunkTag & System.IO.Path.GetExtension(filename)
            End If
            newfilename = filename
            Return filename
        End Function
    End Class


  2. Kiril Vandov
    Kiril Vandov avatar
    323 posts

    Posted 30 Jul 2015 Link to this post

    Hello David,

    I have investigated the provided code snippets and here is what I have found:
    The GetFilePath() method of the handler is called correctly with different file names. I have noticed that you are using setting a local variable ResultChunkTag which is set only when the ProcessStream() is called only once for the current session. Then when you call you local private method GetFileName you are executing the following logic:
    If ResultChunkTag <> Nothing Then
                filename = ResultChunkTag & System.IO.Path.GetExtension(filename)
            End If
    the new fileName is set to be ResultChunkTag, when called for the second file the ProcessStream is not called second time and the guid is the same, making the file with the same name and failing to save it.

    I would suggest you to use the IsNewFileRequest() override and set the ResultChunkTag guid there instead of setting it in the ProcessStream.

    I hope this information helps.

    Kind regards,
    Kiril Vandov
    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 Feedback Portal and vote to affect the priority of the items
  3. DevCraft banner
Back to Top