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

How to select a folder instead of individual files

6 Answers 62 Views
CloudUpload
This is a migrated thread and some comments may be shown as answers.
Neil
Top achievements
Rank 1
Neil asked on 18 Jul 2018, 10:19 AM

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?

6 Answers, 1 is accepted

Sort by
0
Accepted
Martin Ivanov
Telerik team
answered on 19 Jul 2018, 12:14 PM
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.
0
Neil
Top achievements
Rank 1
answered on 19 Jul 2018, 02:50 PM

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;
            });
    }
}
0
Martin Ivanov
Telerik team
answered on 20 Jul 2018, 11:31 AM
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.
0
Neil
Top achievements
Rank 1
answered on 23 Jul 2018, 01:10 PM

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?

 

0
Martin Ivanov
Telerik team
answered on 25 Jul 2018, 09:20 AM
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.
0
Neil
Top achievements
Rank 1
answered on 25 Jul 2018, 12:48 PM
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.
Tags
CloudUpload
Asked by
Neil
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Neil
Top achievements
Rank 1
Share this question
or