How to format the data returned from a Search operation

I am trying to get the Search facility to work correctly.  I can return a list of matching files and folders to the FileManager control, but I am unable to ‘Open’ folders.  It appears that the tree structure gets invalidated and so cannot open the folder. 

This list is returned from the Microsoft Graph API.  DriveItem is a Microsoft object (https://docs.microsoft.com/en-us/graph/api/resources/driveitem?view=graph-rest-1.0)

What values are required in the returned FileManagerDirectoryContent objects (especially the FilterPath and Path values) and how are those values used by the FileManager control when submitting the request to Open the folder?  I think maybe the root folder id or path (in the cwd variable) and the id or path for the selected folder may not be correct.

 

Here is the code I have for the ‘Search’.

    public override FileManagerResponse Search(string path, string searchString, bool showHiddenItems, bool caseSensitive, params FileManagerDirectoryContent[] data)

        {   

            FileManagerResponse searchResponse = new FileManagerResponse();

            try

            {

                DriveItem driveItem = sp.GetDriveItem(data[0].Id);

                FileManagerDirectoryContent cwd = new FileManagerDirectoryContent();

                cwd.Id = driveItem.Id;

                cwd.Name = driveItem.Name;

                cwd.IsFile = driveItem.Folder == null ? true : false;

                cwd.Size = driveItem.Size != null ? long.Parse(driveItem.Size.ToString()) : 0;

                cwd.DateCreated = driveItem.CreatedDateTime.HasValue ? driveItem.CreatedDateTime.Value.DateTime : DateTime.MaxValue;

                cwd.DateModified = driveItem.LastModifiedDateTime.HasValue ? driveItem.LastModifiedDateTime.Value.DateTime : DateTime.MaxValue;

                cwd.Type = driveItem.Folder == null ? new FileInfo(driveItem.Name).Extension : "folder";

                cwd.Action = sp.CreateLink(driveItem.Id).Link.WebUrl;              

                cwd.Path = driveItem.ParentReference.Path;

                cwd.FilterPath = driveItem.ParentReference.Path;               

                cwd.HasChild = DirectoryHasChildren(driveItem.Id);

 

                searchResponse.CWD = cwd;

 

                IEnumerable<DriveItem> searchList = sp.Search(driveItem.Id, searchString);

                List<FileManagerDirectoryContent> returnList = searchList.Where(x => x.Name.Contains(searchString, StringComparison.CurrentCultureIgnoreCase)).Select(x => new FileManagerDirectoryContent()

                {

                    Id = x.Id,

                    Name = x.Name,

                    Size = x.Size != null ? long.Parse(x.Size.ToString()) : 0,

                    DateCreated = x.CreatedDateTime.HasValue ? x.CreatedDateTime.Value.DateTime : DateTime.MaxValue,

                    DateModified = x.LastModifiedDateTime.HasValue ? x.LastModifiedDateTime.Value.DateTime : DateTime.MaxValue,

                    Type = x.Folder == null ? new FileInfo(x.Name).Extension : "folder",

                    HasChild = DirectoryHasChildren(x.Id),  

                    IsFile = x.Folder == null ? true : false,

                    FilterPath = BuildFilterPathName(x),

                    Action = x.Folder == null ? null : sp.CreateLink(x.Id).Link.WebUrl

                }).ToList();

 

                searchResponse.Files = returnList;

                return searchResponse;

            }

            catch (Exception e)

            {

                return GraphExceptionHandler.FormatMessage(e);

            }

        }

 

   private string BuildFilterPathName(DriveItem item)

        {

            string value = GetFilterPathName(item);

            pathValues = new List<string>();

            return value;

        }

 

  private string GetFilterPathName(DriveItem item)

        {

            if (item.ParentReference != null)

            {

                DriveItem x = sp.GetDriveItem(item.ParentReference.Id);

 

                if (x.Name != "root")

                {

                    pathValues.Add(x.Name);

                    GetFilterPathName(x);

                }

            }

            return (string.Join(@"\", pathValues.ToArray().Reverse()) + @"\");

        }

 

View after the ‘Search’ has returned.


 

View as the ‘Open’ is processing (attempting to open the second ‘Fees’ folder in the list).  Notice that the tree has changed!


 

The folder in question is not a sub folder of the root but at a lower level in the tree


1 Reply

SP Sowmiya Padmanaban Syncfusion Team December 11, 2020 12:51 PM UTC

Hi James Cullis,  
 
Greetings from Syncfusion support. 
 
We have checked your requirement with FileManager component ( send the request and response data for open (read) action ).  
 
Please, refer the below video footage for better understanding of your requirement. 
 
 
(If the opened folder is /Fees, then first you need to send the read request for root path (Shared Cases) and then Fees folder ) 
 
Each read request should be in the following format. 
 
Request data: 
 
 
 
Returned response: 
 
 
 
Please, refer the below link for FileManager response. 
 
 
Please let us know, if you need any further assistance. 
 
Regards,  
Sowmiya.P 


Loader.
Up arrow icon