Bug Report T302849
Visible to All Users

ASPxFileManager - FileManagerItem.Id property returns Name and not Id when binding the control to a custom provider

created 9 years ago

[DevExpress Support Team: CLONED FROM T295902: ASPxFileManager - FileManagerItem.Id property returns Name and not Id when binding a control to a data source]
Dear Sirs,
sorry - but the hotfix is not working -
for example:
Public Overrides Function GetLastWriteTime(ByVal file As FileManagerFile) As DateTime
file.folder.id '< wrong…
End Function
The file contains the property folder. the folder.id is not the id but the path…
Kind Regards…

Answers approved by DevExpress Support

created 9 years ago (modified 8 years ago)

We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

Additional information:

We have fixed this issue in the next version of our controls: starting with version 15.1.10, the FileManagerItem.ID  property will contain a folder identifier. However, there is still one important detail that should be implemented in your project.

ASPxFileManager doesn't provide the ID value for a root folder of the custom file system because the control cannot determine the root folder in a custom file system. So, it is necessary to explicitly identify the root folder in the arguments of the FileSystemProvider using an empty relative name as shown below:

Visual Basic
Protected Function FindFolderItem(ByVal folder As FileManagerFolder) As FileSystemData If String.IsNullOrEmpty(folder.RelativeName) Then Return GetRootFolder() End If Dim folders = DataSource.Where(Function(x) x.IsFolder) Return ( _ From item In folders _ Where item.IsFolder AndAlso item.Id.ToString = folder.Id _ Select item).FirstOrDefault() End Function
C#
protected FileSystemData FindFolderItem(FileManagerFolder folder) { if (string.IsNullOrEmpty(folder.RelativeName)) { return GetRootFolder(); } var folders = DataSource.Where(x => x.IsFolder); return (from item in folders where item.IsFolder && item.Id.ToString() == folder.Id select item).FirstOrDefault(); }

I have attached the modified project to my answer.

    created 9 years ago

    In this scenario, the Id property value should be manually passed in the FileSystemProviderBase.GetFiles / FileSystemProviderBase.GetFolders  method using the corresponding overloads:
    FileManagerFolder(FileSystemProviderBase provider, FileManagerFolder parentFolder, string name, string id)
    FileManagerFile(FileSystemProviderBase provider, FileManagerFolder parentFolder, string fileName, string id)

    I've attached a sample and a video illustrating this approach in action.

    If your scenario is different, feel free to modify the attached sample or send us your own runnable project where the problem exists.

    Thanks,
    Artem

      Show previous comments (4)
      DevExpress Support Team 9 years ago

        Hello,

        I was able to reproduce the issue, and it appears that not all the FileManagerItems have a correct Id. For example, when a FileManagerFile instance is created, its Folder object is created again (instead of assigning the reference to the FileManagerFolder object passed in the constructor parameter). That is why in certain scenarios (when you have files in a folder, this folder cannot be found in the FindFileItem method), you get the NullReference error.

        Taking this into account, I have found why ASPxFileManager was not working: the root folder has the Id = "" (empty string). I suggest you update the FindFolderItem method in order to run your application:

        C#
        Protected Function FindFolderItem(ByVal folder As FileManagerFolder) As FileSystemData Dim folders = DataSource.Where(Function(x) x.IsFolder) If folder.Id = "" Then Return folders.First() End If   Return ( _ From item In folders _ Where item.IsFolder AndAlso item.Id.ToString = folder.Id _ Select item).FirstOrDefault() End Function

        The main issue is the FindFileItem method. Here, the following line returns Nothing:

        C#
        Protected Function FindFileItem(ByVal file As FileManagerFile) As FileSystemData Dim folderItem As FileSystemData = FindFolderItem(file.Folder)

        This happens because the file.Folder does not reference the custom folder you created, but references the base class folder with an auto-generated Id that is a relative path to the file.
        I suggest you change this method, so that you can pass a new FileManagerFolder instance (with your custom Id) and not the file.Folder reference into the FindFolderItem method.

        I have passed this ticket to our developers for further research. We will update this ticket as soon as we get any results.

        BK BK
        Bagus Kusuma 1 9 years ago

          HI,

          It seems I have same problem, FindFileItem function return null coz relativename from FileManager contain more path,ie:
          rootParentFolder\ChildFolder\SubchildFolder\filename.extension

          Meanwhile, GetRelativeName function called by FindFolderItem return not complete as from FileManager properties
          It's always return \ChildFolder\SubchildFolder\filename.extention

          DevExpress Support Team 9 years ago

            Hello,

            If you are using a version older than 15.1.10, I suggest that you upgrade our components to v15.1.10 or to v15.2.9 (if you are using the 15.2 build). These versions contain fixes for this issue. If the problem persists, please create a new ticket dedicated to the issue and describe it in greater detail. We will also appreciate it if you attach a test project for research.

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.