KeyNotFoundException when setting e.NewFileStream

2 posts, 0 answers
  1. Tyler
    Tyler avatar
    32 posts
    Member since:
    Jun 2011

    Posted 20 Oct 2011 Link to this post

    I'm creating a RadUpload control in code when I try to change the stream for the file being uploaded I get the following exception.  The stream gets uploaded but seems to be missing part of the contents.   The initial file that is being added to ValidFiles is just there as a placeholder so that the FileUploadStarting event will fire.

    The given key was not present in the dictionary.

       at System.ThrowHelper.ThrowKeyNotFoundException()
       at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
       at Telerik.Windows.Controls.RadUpload.OnFileUploadSizeChanged(Object sender, EventArgs e)


    RadUpload upload = new RadUpload();
                upload.TargetFolder = "UserUploads";
                upload.OverwriteExistingFiles = true;
                upload.UploadServiceUrl = "../FileUploadHandler.ashx";
                upload.CurrentSession.ValidFiles.Add(file.Name, new RadUploadSelectedFile(file));
     
                upload.FileUploadStarting += new System.EventHandler<FileUploadStartingEventArgs>(upload_FileUploadStarting); 
                upload.UploadFinished += new RoutedEventHandler(upload_UploadFinished);
     
                upload.StartUpload();
    void upload_FileUploadStarting(object sender, FileUploadStartingEventArgs e)
    {
        e.NewFileStream = GetCsvStream();
    }

  2. Tyler
    Tyler avatar
    32 posts
    Member since:
    Jun 2011

    Posted 21 Oct 2011 Link to this post

    Found the answer had to use SelectedFiles instead of ValidFiles and call PrepareSelectedFilesForUpload()
    upload.CurrentSession.SelectedFiles.Add(new RadUploadSelectedFile(file));             
    upload.PrepareSelectedFilesForUpload();

  3. DevCraft banner
Back to Top