How to select a folder instead of individual files

7 posts, 1 answers
  1. Neil
    Neil avatar
    4 posts
    Member since:
    Jul 2018

    Posted 18 Jul 2018 Link to this post

    I'm looking for a way of not just selecting files for upload but entire folder structures. I was hoping I could use the CreateOpenFileDialog delegate to return the RadOpenFolderDialog however this function expects a return type of Microsoft.Win32.OpenFileDialog which the Telerik controls do not inherit from.

    Any suggestions?

  2. Answer
    Martin Ivanov
    Admin
    Martin Ivanov avatar
    2065 posts

    Posted 19 Jul 2018 Link to this post

    Hello Neil,

    You are right. The CreateOpenFileDialog delegate returns an object of type OpenFileDialog which is not the base class of the RadFileDialog controls.

    To achieve your requirement you can hide the default Browse button via the Buttons property of RadCloudUpload, and then add a new button over the control. When you click the new button you can open a new folder dialog and when you choose a folder you can get its file names and add them in the cloud upload programmatically.

    I hope that helps.

    Regards,
    Martin Ivanov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Neil
    Neil avatar
    4 posts
    Member since:
    Jul 2018

    Posted 19 Jul 2018 in reply to Martin Ivanov Link to this post

    Thanks for your response. Since posting I have actually solved the problem by implementing drag and drop from Windows Explorer which, as you suggest, programmatically adds the files to the upload control. I had to do some interesting things in order to retain folder structure though as the default implementation only takes the filename when calling the upload provider!

    public interface IDocumentTransferProvider : ICloudUploadProvider
    {
        string DestinationPath { get; set; }
        IDocumentDirectory Destination { get; set; }
    }
     
    public class DocumentTransferProvider : IDocumentTransferProvider
    {
        public string DestinationPath { get; set; }
        public IDocumentDirectory Destination { get; set; }       
     
        public Task<object> UploadFileAsync(string fileName, Stream fileStream, CloudUploadFileProgressChanged uploadProgressChanged, CancellationToken cancellationToken)
        {
            if (!string.IsNullOrEmpty(DestinationPath))
                fileName = $"{DestinationPath}/{fileName}";
     
            return Destination.CopyTo(fileStream, fileName, new DocumentTransferProgressHandler(uploadProgressChanged), cancellationToken)
                .ContinueWith<object>(t =>
                {
                    if (t.Exception != null)
                        Logger.Exception(t.Exception);
     
                    return t.IsCompleted;
                });
        }
    }
  4. Martin Ivanov
    Admin
    Martin Ivanov avatar
    2065 posts

    Posted 20 Jul 2018 Link to this post

    Hello Neil,

    It is nice to hear that you've found a solution for your case. Thank you for sharing your code.

    Regards,
    Martin Ivanov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  5. Neil
    Neil avatar
    4 posts
    Member since:
    Jul 2018

    Posted 23 Jul 2018 Link to this post

    Hi,

    I've just encountered another issue with the Cloud Upload control. It seems that if I use the "Cancel" button mid transfer I am getting a state transition from "Cancelling" to "Uploaded". Surely it should end up on the "Cancelled" state?

     

  6. Martin Ivanov
    Admin
    Martin Ivanov avatar
    2065 posts

    Posted 25 Jul 2018 Link to this post

    Hello Neil,

    I've tested this but I wasn't able to reproduce it. Can you take a look at the attached project and let me know if I am missing anything?

    Regards,
    Martin Ivanov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  7. Neil
    Neil avatar
    4 posts
    Member since:
    Jul 2018

    Posted 25 Jul 2018 in reply to Martin Ivanov Link to this post

    Ok, after looking at your sample it turns out it was because I was not letting the task cancellation exception to flow back up the stack as I was running the upload asynchronously but using a ContinueWith at the end to check for success. This was swallowing the cancellation exception so the CloudUpload control did not know that the file was cancelled.
Back to Top