RadUpload - Casting UploadedFiles to FileInfo[] for Queuing

3 posts, 1 answers
  1. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 18 Nov 2011 Link to this post

    Hello,

    I am trying to queue all my uploaded documents using RadUpload.
    I can queue easily using Drag n Drop, however I am having difficulties casting the uploadedFiles from RadUpload to FileInfo[]. 
    Sections of the working DragnDrop and the Not-working RadUpload are included below. 

    How do I cast my UploadedFiles to FileInfo[] ???
    Thank You.



    private void ImageDrop_Drop(object sender, DragEventArgs e)
    {
                // Queue the FileInfo objects representing dropped files
                files = e.Data.GetData(DataFormats.FileDrop) as FileInfo[];
    ................................
    }
     
    private void RadUpload1_UploadFinished(object sender, RoutedEventArgs e)
    {
                 
                files = RadUpload1.CurrentSession.UploadedFiles as FileInfo[];
    ....................................
    }
  2. Answer
    Tina Stancheva
    Admin
    Tina Stancheva avatar
    3298 posts

    Posted 23 Nov 2011 Link to this post

    Hi Jay,

    The RadUpload1.CurrentSession.UploadedFiles collection is of type Collection<RadUploadSelectedFile> so each item in it is of type RadUploadSelectedFile and this is why you cannot cast it to a FileInfo type. But the RadUploadSelectedFile class exposes a File property of type FileInfo which you can use instead:
    private void RadUpload1_UploadFinished(object sender, RoutedEventArgs e)
    {
        var files = new List<FileInfo>();
        foreach (RadUploadSelectedFile uploadedFile in RadUpload1.CurrentSession.UploadedFiles)
        {
            files.Add(uploadedFile.File);
        }
    }
    Give this approach a try and let us know how it goes.

    All the best,
    Tina Stancheva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. jay
    jay avatar
    39 posts
    Member since:
    Jun 2010

    Posted 23 Nov 2011 Link to this post

    Thanks for your feedback. I had stumbled onto this yesterday.
Back to Top