This is a migrated thread and some comments may be shown as answers.

upload handler .... new filename not changing

1 Answer 43 Views
Upload
This is a migrated thread and some comments may be shown as answers.
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
David Ocasio asked on 27 Jul 2015, 04:11 PM

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
        Get
            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
        Get
            ' 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
        MyBase.ProcessStream()
    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

 

1 Answer, 1 is accepted

Sort by
0
Kiril Vandov
Telerik team
answered on 30 Jul 2015, 09:44 AM
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
Telerik
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
Tags
Upload
Asked by
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Kiril Vandov
Telerik team
Share this question
or